web*_*per 0 java spring template-engine spring-mvc thymeleaf
我是第一次练习百里香模板引擎.我已经按照教程等等,但我不知道我哪里出错了.
我的控制器:
public String mainPage(Model model){
model.addAttribute("data", "Hello Thymeleaf");
return "main";
}
Run Code Online (Sandbox Code Playgroud)
我的HTML如下:
<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<h1>th:text="${data}"</h1>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
当我点击localhost时,它显示th:text ="$ {data}"而不是Hello Thymeleaf
<h1>"${data}"</h1>
Run Code Online (Sandbox Code Playgroud)
也不起作用.查看解析程序配置必须正确,因为它将main解析为main.html.我正在使用spring4 SpringTemplateEngine和spring4百万美元视图解析器.
提前致谢
你必须使用 th:text
<h1 th:text="${data}"></h1>
Run Code Online (Sandbox Code Playgroud)
或者如果您不想使用该th:text属性,则必须使用th:inline="text"并使百里香叶在标签内渲染上下文.但要确保你把变量中[[和]]
<h1 th:inline="text">[[${data}]]</h1>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6744 次 |
| 最近记录: |