**
springboot的templates用法
**
@Controller
public class HelloController {
@RequestMapping("/test")
public String test(Model model){
model.addAttribute("msg","<h1>templates测试</h1>");
model.addAttribute("users", Arrays.asList("lishao","liyuan"));
return "/test";
}
}
在controller中添加视图
在html中调用
<body>
<h3>test</h3>
<!--不转义-->
<div th:text="${msg}"></div>
<!--转义h1-->
<div th:utext="${msg}"></div>
<hr>
<h3 th:each="user : ${users}" th:text="${user}"></h3>
</body>
记得要导入templates的依赖
当你导入了templates依赖,