Spring MVC - ParameterizableViewController Example

[Updated: Jul 24, 2017, Created: Jul 24, 2017]

In this example we are going to use ParameterizableViewController directly to map URL to a view instead of using ViewControllerRegistry.


The configuration class

public class Main {
  public ParameterizableViewController myViewController () {
      ParameterizableViewController c = new ParameterizableViewController();
      return c;
  public HandlerMapping myHandlerMapping () {
      SimpleUrlHandlerMapping m = new SimpleUrlHandlerMapping();
      Map<String, Object> map = new HashMap<>();
      map.put("/test", myViewController());
      return m;
  public static void main (String[] args) {
      SpringApplication.run(Main.class, args);

In above configuration, we are mapping path '/test' to view 'myView'.

The View


  <body style="margin:20px;">
  JSP view

      Response Status: <%=response.getStatus() %>

Spring Boot properties


spring.mvc.view.prefix= /WEB-INF/pages/
spring.mvc.view.suffix= .jsp

Running web application

mvn spring-boot:run


Example Project

Dependencies and Technologies Used :

  • spring-boot-starter-web 1.5.4.RELEASE: Starter for building web, including RESTful, applications using Spring MVC. Uses Tomcat as the default embedded container.
    Corresponding Spring version: 4.3.9.RELEASE
  • tomcat-embed-jasper 8.5.15: Core Tomcat implementation.
  • JDK 1.8
  • Maven 3.3.9

Spring Parameterizable View Controller Example Select All Download
  • parameterizable-view-controller-example
    • src
      • main
        • java
          • com
            • logicbig
              • example
        • resources
        • webapp
          • WEB-INF
            • pages

See Also