一. 回顾
前面Day27——thymeleaf的使用,讲述了thymeleaf的使用。今天讲述thymeleaf的语法。
二. 语法
三. 例子
HelloController.java
@RequestMapping("/success")
public String success(Map<String, Object> map){
map.put("hello", "<h1>你好</h1>");
map.put("users", Arrays.asList("zhangsan","lisi","wangwu"));
return "success";
}
success.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>title</title>
</head>
<body>
<h1>成功!</h1>
<!-- th:text 将文本内容设置为指定的词-->
<div th:text="${hello}"></div>
<div th:utext="${hello}"></div>
<!--th:each每次遍历都会生成当前标签-->
<h4 th:text="${user}" th:each="user:${users}"></h4>
<h4>
<span th:each="user: ${users}"> [[ ${user} ]] </span>
</h4>
</body>
</html>
测试结果如下: