For a simple example, on the basis of the QuickStart project, take a simple example to render a page through 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.
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.
Distributed micro-service Cloud Architecture development Web application