maven构建简单项目
修改pom文件添加thymeleaf的坐标
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency>
templates:该目录是安全的,意味着该目录下的内容是不允许外界直接访问的(不能通过url直接访问)。
Thymeleaf是通过他特定的语法对html的标记做渲染。
/** * Thymeleaf 入门案例 */ @Controller public class DemoController { @RequestMapping("/show") public String showInfo(Model model) { model.addAttribute("msg","Thymeleaf 第一个案例"); return "index"; } }
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Thymeleaf 入门</title> </head> <body> <span th:text="Hello"></span> <hr/> <span th:text="${msg}"></span> </body> </html>
有可能会出现没有html结束标记的异常: 我的项目的Springboot的版本是2.1.2所以没有出现此异常 加上结束标记即可。让html的标记按照严谨的语法编写。 修改导入的Thymeleaf的jar包的版本到 3.0以上
有可能会出现没有html结束标记的异常: 我的项目的Springboot的版本是2.1.2所以没有出现此异常
<properties> <thymeleaf.version>3.0.2.RELEASE</thymeleaf.version> <thymeleaf-layout-dialect.version>2.0.4</thymeleaf-layout-dialect.version> </properties>
原文链接:https://www.cnblogs.com/net-safe/p/13529126.html