参考: http://blog.csdn.net/u012706811/article/details/52185345
默认视图解析
spring-boot很多配置都有默认配置,比如默认页面映射路径为 classpath:/templates/*.html 同样静态文件路径为 classpath:/static/编写模板文件
编写模板文件src/main/resouces/templates/hello.html: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3"> <head> <meta charset="UTF-8"></meta> <title>Hello World</title> </head> <body> <h1>thymeleaf demo</h1> <p th:text="${name}"></p> </body> </html>html模板标签需要闭合
编写模板文件controller
@Controller @RequestMapping("templates") public class TemplatesController { @RequestMapping("thymeleaf") public String thymeleafTemplates(Map<String,Object> map){ map.put("name","tom"); return "Hello"; } }