SPRINGMVC Integrated thymeleaf template
The previous work used the Thymeleaf view template, it really feels good to use, the following describes the next Springmvc + thymeleaf template Integration
Thymeleaf, the official Pet shop on GitHub, Https://github.com/thymeleaf/thymeleafexamples-petclinic, can be downloaded on GitHub.
The following is an introduction to the integrated approach: the construction of the project on the SPRINGMVC is not much introduced. There are many examples available online This article is about how to join the Thymeleaf template 1. Introducing the Thymeleaf package
Maven Project Words
<thymeleaf.version>2.1.3.RELEASE</thymeleaf.version>
<dependency>
<groupId> org.thymeleaf</groupid>
<artifactId>thymeleaf</artifactId>
<version>${ thymeleaf.version}</version>
</dependency>
<dependency>
<groupId> org.thymeleaf</groupid>
<artifactId>thymeleaf-spring3</artifactId>
<version>${ Thymeleaf.version}</version>
If it's not a MAVEN project, download the relevant package yourself 2. Change the necessary configuration
The configuration file for the XML in SPRINGMVC is configured as follows (according to the configuration of the pet instance)
<!--use Thymeleaf--<bean id= "Templateresolver" class= "ORG.THYMELEAF.TEMPLATERESOLVER.SERVL Etcontexttemplateresolver "> <property name=" prefix "value="/thymeleaf/"/> <property name= "Suffix" value= ". html"/> <property name= "Templatemode" value= "HTML5"/> <!--Template CAC He is set to False (default is True). --<property name= "cacheable" value= "false"/> <property name= "characterencoding" value= "
UTF-8 "/> </bean> <bean id=" Templateengine "class=" Org.thymeleaf.spring3.SpringTemplateEngine "> <property name= "Templateresolver" ref= "Templateresolver"/> </bean> <!---T He contentnegotiatingviewresolver delegates to the Internalresourceviewresolver and Beannameviewresolver,-and uses
The requested media type (determined by the path extension) to pick a matching view. -When THe media type is ' text/html ', it'll delegate to the Internalresourceviewresolver's Jstlview,-otherwise to the B
Eannameviewresolver. --<bean class= "Org.springframework.web.servlet.view.ContentNegotiatingViewResolver" > <proper Ty name= "Contentnegotiationmanager" ref= "Cnmanager"/> <property name= "Viewresolvers" > &L T;list> <!--used here for ' xml ' and ' atom ' views--<bean class= ' Org.s
Pringframework.web.servlet.view.BeanNameViewResolver "> <property name=" Order "value=" 1 "/>
</bean> <bean class= "Org.thymeleaf.spring3.view.ThymeleafViewResolver" > <property name= "Templateengine" ref= "Templateengine"/> <property name=
"Characterencoding" value= "UTF-8"/> <property name= "Order" value= "2"/> <!--We need to set exclusions because Content negotiation tries to resolve from--< !--Thymeleaf Even if a specific view bean (of a different Class) is already-<!--found , which might cause exceptions (e.g Thymeleafview does not having a--<!--' Marshaller ' p Roperty).
--<property name= "Excludedviewnames" value= "*.xml"/> </bean> <!--Default Viewclass:jstl view (JSP with HTML output)--<bean class= "Org.s Pringframework.web.servlet.view.InternalResourceViewResolver "> <property name=" prefix "value=" /views/"/> <property name=" suffix "value=". jsp "/> <property name="
Order "value=" 3 "/> </bean> </list> </property> </bean> <!--strategy:only path extension is taken to account--
> <bean id= "Cnmanager" class= "Org.springframework.web.accept.ContentNegotiationManagerFactoryBean" > <property name= "Favorpathextension" value= "true"/> <property name= "Ignoreacceptheader" value= "true"/
> <property name= "defaultcontenttype" value= "text/html"/> <property name= "MediaTypes" > <map> <entry key= "html" value= "text/html"/> <entry key=
"xml" value= "Application/xml"/> <entry key= "Atom" value= "Application/atom+xml"/> </map> </property> </bean>
That's fine, but the official pet store example doesn't involve Chinese, which is something we need to be aware of.
Bean id= "templateresolver" class= "Org.thymeleaf.templateresolver.ServletContextTemplateResolver" The addition of this bean allows the page to be displayed correctly in Chinese.
Bean class= "org.thymeleaf.spring3.view.ThymeleafViewResolver" this bean can be the normal display of Chinese in the data
The use of thymeleaf in the page, according to the thymeleaf syntax.
In addition, attached to my coding.net above the integration of the source code, point right Https://coding.net/u/nanhu/p/spring_myBatis_Thymeleaf/git