Freemark templates and Thymeleaf templates 1. Introduction of Thymeleaf and Freemark in Pom.xml;
<dependency> <groupId>org.springframework.boot</groupId> <artifactId> Spring-boot-starter-thymeleaf</artifactid></dependency><dependency> <groupId> Org.springframework.boot</groupid> <artifactid>spring-boot-starter-freemarker</artifactid ></dependency>
2. Configuring in Application.xml
########################################################## #THYMELEAF (thymeleafautoconfiguration) ############## ########################################## #spring. thymeleaf.prefix=classpath:/templates/# spring.thymeleaf.suffix=.html#spring.thymeleaf.mode=html5#spring.thymeleaf.encoding=utf-8#;charset=< Encoding> is added#spring.thymeleaf.content-type=text/html # set to False for hot refreshspring.thymeleaf.cache= False ########################################################## #FREEMARKER (freemarkerautoconfiguration) ####### ################################################ #spring. freemarker.allow-request-override= falsespring.freemarker.cache=truespring.freemarker.check-template-location=truespring.freemarker.charset= utf-8spring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes= falsespring.freemarker.expose-session-attributes=falsespring.freemarker.expose-spring-macro-helpers=false# spring.freemarker.prefix= #spring. freemarker.request-context-attribute= #spring. Freemarker.settings.*= #spring. freemarker.suffix=.ftl#spring.freemarker.template-loader-path=classpath:/ templates/#comma-separated list#spring.freemarker.view-names= # Whitelist of view names that can be resolved
3. Writing a template
Note that the path is the default in the configuration and can be modified <! DOCTYPE html>
4.controller LayerPackage Com.ithuan.demo.controller;import Java.util.map;import Org.springframework.stereotype.controller;import Org.springframework.web.bind.annotation.RequestMapping, @Controller//@RequestMapping ("/templates") public class Templatecontroller {@RequestMapping ("/hello1111") public String Hello1 (map<string,object> Map) { SYSTEM.ERR.PRINTLN ("----"); Map.put ("Hello", "from templatecontroller.hellohtml"); return "Hello1";} @RequestMapping ("/hello22") public String hello22 (map map) {System.err.println ("2222"); Map.put ("Hello", "final Big Boss"); return "Freemakr";}}
JSP page show comes with parsing no longer showingSpringboot in Template freemark,thymeleaf,jsp