Springboot supports Thymeleaf, Freemarker, JSP, but the official does not recommend using JSP, because some features will be limited, here is a description of Thymeleaf and Freemarker.
One, thymeleaf template
The front-end interface of the Thymeleaf template is an. html format file that can be viewed directly using a browser to facilitate the debugging of styles. 1. Pom Dependencies Add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-thymeleaf</artifactid>
</dependency>
Viewing the Maven affinity tree through MVN dependency:tree, you find that Thymeleaf automatically relies on importing Web packages, so you no longer have to import Web packages. 2. Application Property Configuration
The default configuration for viewing official documents is described below:
It must be noted here that the development of the time to turn off the template cache, or modify the interface file can not be displayed in real time. To turn off the template cache in the Application.properties file:
Spring.thymeleaf.cache=false
After the cache is turned off, the HTML file is modified so that it can be directly ctrl+f9 compiled to display the latest modifications. 3, the writing interface
My interface hello.html path is: templates/template/hello.html, code:
<! DOCTYPE html>
4, the preparation of controller
Package com.example.demo.template;
Import Org.springframework.stereotype.Controller;
Import Org.springframework.ui.Model;
Import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping ("/html") public
class Htmlcontroller {
@RequestMapping ("/hello")
Public String Hello (model model) {
model.addattribute (' name ', ' World ');
return "Template/hello";
}
Run the access as follows:
thymeleaf Specific Use reference
http://blog.csdn.net/z719725611/article/details/53908294 II, freemarker template 1, pom dependencies add
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId> Spring-boot-starter-freemarker</artifactid>
</dependency>
Note: Allow Thymeleaf and freemarker to exist at the same time 2, Application property configuration
The default configuration for viewing official documents is described below:
application.properties files need not be configured, use the default configuration 3, write the interface
My interface HELLO.FTL path is: TEMPLATES/FTL/HELLO.FTL, code:
<! DOCTYPE html>
4, the preparation of controller
Package com.example.demo.template;
Import Org.springframework.stereotype.Controller;
Import org.springframework.web.bind.annotation.RequestMapping;
Import Java.util.Map;
@Controller
@RequestMapping ("/FTL") public
class Freemarkercontroller {
@RequestMapping ("/hello") Public
String Hello (map<string,object> Map) {
map.put (' message ', ' Hello,world ');
return "Ftl/hello";
}
Then start running.
Freemarker Specific Use reference
http://blog.csdn.net/fhx007/article/details/7902040/
http://blog.csdn.net/tang9140/article/details/39695653