Code address
Http://github.com/dingxiaobo/multi-view-resolver
Parse JSP pages and thymeleaf pages separately with two dispatcher
Pom.xml
... <!--Thymeleaf - <!--Https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf - <Dependency> <groupId>Org.thymeleaf</groupId> <Artifactid>Thymeleaf</Artifactid> <version>3.0.6.RELEASE</version> </Dependency> <!--Https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 - <Dependency> <groupId>Org.thymeleaf</groupId> <Artifactid>Thymeleaf-spring4</Artifactid> <version>3.0.6.RELEASE</version> </Dependency> <!--JSP Tag Library - <!--Https://mvnrepository.com/artifact/javax.servlet.jsp.jstl/javax.servlet.jsp.jstl-api - <Dependency> <groupId>Javax.servlet.jsp.jstl</groupId> <Artifactid>Javax.servlet.jsp.jstl-api</Artifactid> <version>1.2.1</version> </Dependency>...
Src/main/resources/spring-jsp.xml
... <!--Configure SPRINGMVC - <!--1. Turn on SPRINGMVC annotation mode - <!--Simplified configuration: 1. Autoenrollment Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter Org.springframewor K.web.servlet.mvc.annotation.defaultannotationhandlermapping 2. Provides a range of functions: Data binding, format @NumberFormat for digital dates @DataTimeFo Rmat,xml,json default read/write support - <Mvc:annotation-driven/> <!--servlet-mapping Map Path "/" action to do - <!--static Resource default servlet handles 1. For example JS CSS 2. Allow/do overall mapping - <Mvc:default-servlet-handler/> <!--3.jsp Display Viewresolver - <BeanID= "Jspresolver"class= "Org.springframework.web.servlet.view.InternalResourceViewResolver"> < Propertyname= "Viewclass"value= "Org.springframework.web.servlet.view.JstlView"/> < Propertyname= "prefix"value= "/web-inf/jsp/"/> < Propertyname= "suffix"value= ". jsp"/> </Bean> <!--Scan web-related packages - <Context:component-scanBase-package= "cn.dxbtech.controller.jsp"/>...
Src/main/resources/spring-thymeleaf.xml
... <!--Configure SPRINGMVC - <!--1. Turn on SPRINGMVC annotation mode - <!--Simplified configuration: 1. Autoenrollment Org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter Org.springframewor K.web.servlet.mvc.annotation.defaultannotationhandlermapping 2. Provides a range of functions: Data binding, format @NumberFormat for digital dates @DataTimeFo Rmat,xml,json default read/write support - <Mvc:annotation-driven/> <!--servlet-mapping Map Path "/" action to do - <!--static Resource default servlet handles 1. For example JS CSS 2. Allow/do overall mapping - <Mvc:default-servlet-handler/> <!--using thymeleaf parsing - <BeanID= "Templateresolver"class= "Org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver"> < Propertyname= "prefix"value= "/web-inf/thymeleaf/"/> < Propertyname= "suffix"value= ". html"/> < Propertyname= "Templatemode"value= "HTML"/> < Propertyname= "cacheable"value= "false"/> </Bean> <BeanID= "Templateengine"class= "Org.thymeleaf.spring4.SpringTemplateEngine"> < Propertyname= "Templateresolver"ref= "Templateresolver"/> </Bean> <Beanclass= "Org.thymeleaf.spring4.view.ThymeleafViewResolver"> < Propertyname= "Templateengine"ref= "Templateengine"/> </Bean> <!--Scan web-related packages - <Context:component-scanBase-package= "Cn.dxbtech.controller.thymeleaf"/>...
Src/main/webapp/web-inf/web.xml
... <!--1. Configure JSP Dispatcher - <servlet> <Servlet-name>Jsp-dispatcher</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <!--Configure the configuration files that need to be loaded - <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring-jsp.xml</Param-value> </Init-param> <Load-on-startup>0</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Jsp-dispatcher</Servlet-name> <Url-pattern>*.do</Url-pattern> </servlet-mapping> <!--2. Configure Thymeleaf Dispatcher - <servlet> <Servlet-name>Thymeleaf-dispatcher</Servlet-name> <Servlet-class>Org.springframework.web.servlet.DispatcherServlet</Servlet-class> <Init-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath:spring-thymeleaf.xml</Param-value> </Init-param> <Load-on-startup>1</Load-on-startup> </servlet> <servlet-mapping> <Servlet-name>Thymeleaf-dispatcher</Servlet-name> <Url-pattern>*.th</Url-pattern> </servlet-mapping>...
Project structure
Run
mvn tomcat7:run
Test
1. Visit http://localhost:8080/jsp.do
2. Visit http://localhost:8080/thymeleaf.th
Spring MVC integrates JSP and thymeleaf two template engines