Spring cloud spring boot mybatis distributed micro service Cloud Architecture Development Web Application

Keywords: Thymeleaf Spring encoding JSP

After completing the configuration, take a simple example. Based on the quick start project, take a simple example to render a page through Thymeleaf.

@Controller
public class HelloController {
 
    @RequestMapping("/")
    public String index(ModelMap map) {
        // Add a property to read from the template
        map.addAttribute("host", "http://blog.didispace.com");
        // return the name of the template file, corresponding to src/main/resources/templates/index.html
        return "index";  
    }
 
}
<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8" />
    <title></title>
</head>
<body>
<h1 th:text="${host}">Hello World</h1>
</body>
</html>

On the above page, directly open the HTML page to show Hello World, but after starting the program, visit http://localhost:8080 /, which shows the value of host in the Controller: http://blog.didispace.com, so as not to break the data logic separation of HTML content.

For more information about the page syntax of Thymeleaf, please visit the official documents of Thymeleaf.

Default parameter configuration of Thymeleaf

If you need to modify the default configuration, just copy the following properties to application.properties and modify them to the required values, such as modifying the extension of the template file, modifying the default template path, etc.

# Enable template caching.
spring.thymeleaf.cache=true 
# Check that 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 from resolution.
spring.thymeleaf.excluded-view-names= 
# Template mode to be 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 be resolved.

Support JSP configuration

Spring Boot is not recommended, but if you have to use it, you can refer to this project as a scaffold: JSP support

Source source technical support for the complete project 1791743380

Posted by Paul Arnold on Tue, 31 Dec 2019 17:03:19 -0800