After the configuration is complete, take a simple example, based on the QuickStart project, to give a simple example to render a page with Thymeleaf
@Controller public class HelloController { @RequestMapping("/") public String index(ModelMap map) { // 加入一个属性,用来在模板中读取 map.addAttribute("host", "http://blog.didispace.com"); // return模板文件的名称,对应src/main/resources/templates/index.html return "index"; } }
<!DOCTYPE html>
As on the page, open the HTML page directly to show Hello World, but after launching the program, access to http://localhost:8080/, is to display the controller in the value of the host:/HTTP Blog.didispace.com, the logical separation of data without destroying the contents of HTML itself.
For more Thymeleaf page syntax, please also visit the THYMELEAF Official document query for use.
Default parameter configuration for Thymeleaf
If you need to modify the default configuration, just copy the following to modify the properties to application.properties, and modify the required values, such as modifying the template file extension, modify the default template path and so on.
# Enable template caching. Spring.thymeleaf.cache=true # Check The templates location exists. Spring.thymeleaf.check-template-location=true # Content-type value. spring.thymeleaf.content-type=text/html # Enable MVC thymeleaf View resolution. Spring.thymeleaf.enabled=true # Template encoding. Spring.thymeleaf.encoding=utf-8 # comma-separated List of view names that should is excluded from resolution. spring.thymeleaf.excluded-view-names= # Template mode to is applied to templates. See also Standardtemplatemodehandlers. SPRING.THYMELEAF.MODE=HTML5 # Prefix that gets prepended to view names when building a URL. spring.thymeleaf.prefix=classpath:/templates/# Suffix that gets appended to view names when building a URL. Spring.thymeleaf.suffix=.html spring.thymeleaf.template-resolver-order= # Order of the template resolver in the chain. spring.thymeleaf.view-names= # comma-separated List of view names that can is resolved.
Spring Cloud Spring Boot mybatis distributed microservices Cloud architecture-Developing Web Applications 2