For a simple example, on the basis of the QuickStart project, take a simple example to render a page through Thymeleaf.
@Controller Public classHellocontroller {@RequestMapping ("/") PublicString Index (Modelmap map) {//add an attribute that is used to read from the templateMap.addattribute ("Host","http://blog.didispace.com"); //the name of the return template file, corresponding to the src/main/resources/templates/index.html return "Index"; } }
<! DOCTYPE html> "en"> <meta charset= "UTF-8" /> <title></title> "${host}">hello world
As on the page, directly open the HTML page to show Hello World, but after launching the program, the access http://localhost:8080/
is to display the controller in the value of host: http://blog.didispace.com
, do not break the HTML itself content of the logical separation of data.
If you need to modify the default configuration, just copy the following to modify the properties into the 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 be excluded fromresolution. 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 resolverinchThe chain. spring.thymeleaf.view-names= # comma-separated List of view names that can is resolved.
Distributed micro-service Cloud Architecture development Web application