使用${}获取值
页面Demo
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'Hello, ' + ${name} + '!'" >hhhh</p>
</body>
</html>
后台Demo
@RequestMapping(value="/hello",method = RequestMethod.GET)
public String helloTheme(Model model){
model.addAttribute("name", "world");
return "/hello";
}
示例
1.后台设置值,页面取值的情况
Paste_Image.png
2.后台不设值,页面取值的情况
Paste_Image.png
3.页面不写th:text="'Hello, ' + ${name} + '!'"的情况
Paste_Image.png