thymeleaf can be said to be the most useful template engine at present, and the integration is also very convenient. Instructions can be found at http://www.thymeleaf.org/.
import dependencies
<dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf</artifactId> <version>3.0.2.RELEASE</version> </dependency> <dependency> <groupId>org.thymeleaf</groupId> <artifactId>thymeleaf-spring4</artifactId> <version>3.0.2.RELEASE</version> </dependency>
spring configuration
<!-- Thymeleaf View Resolver - implementation of Spring's ViewResolver interface --> <bean id="viewResolver" class="org.thymeleaf.spring4.view.ThymeleafViewResolver"> <property name="templateEngine" ref="templateEngine" /> <property name="characterEncoding" value="UTF-8" /> </bean> <!-- Thymeleaf Template Engine (Spring4-specific version) --> <bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine"> <property name="templateResolvers"> <set> <ref bean="templateResolver" /> </set> </property> </bean> <!-- Thymeleaf Template Resolver --> <bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver"> <property name="prefix" value="/" /> <property name="templateMode" value="HTML" /> </bean>
In this way, all html pages in the root directory of the web application will be parsed with thymeleaf.
If you think my article helped you, please buy me a drink! I will be very grateful and insist to help you all more!