标签:mapping asList depend 判断 html res ESS title 默认
静态资源默认存放在resources下的public, resources, static目录, 而且同名优先级比较resources>static>public
在静态资源目录中的index.html会成为首页
templates目录下的所有页面只能通过controller来跳转, 相当于WEB-INF, 需要模板引擎提供视图解析器来驱动
导入依赖
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring5</artifactId>
</dependency>
<dependency>
<groupId>org.thymeleaf.extras</groupId>
<artifactId>thymeleaf-extras-java8time</artifactId>
</dependency>
controller
@RequestMapping("/test")
public String index(Model model) {
model.addAttribute("msg", "<h1>hello thymeleaf</h1>");
model.addAttribute("users", Arrays.asList("野比大雄", "野原新之助"));
return "test";
}
test.html
<!DOCTYPE html>
<!--加入约束-->
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<!--不会转义-->
<div th:text="${msg}"></div>
<!--会转义-->
<div th:utext="${msg}"></div>
<hr>
<!--从users中遍历出所有的元素-->
<h1 th:each="user:${users}" th:text="${user}"></h1>
<!--行内写法-->
<h1 th:each="user:${users}">[[${user}]]</h1>
</body>
</html>
标签:mapping asList depend 判断 html res ESS title 默认
原文地址:https://www.cnblogs.com/pinked/p/12340094.html