我是百里香的全新人物。刚才读到它,现在,我试图在前端使用百里香叶显示一些文本,从后端获取spring mvc的值。
successPwd.html
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
<meta charset="UTF-8"/>
<title>Password Change</title>
</head>
<body>
<h2>Password Changed</h2>
Your password has been changed. Your account information is below.
Username: [[${account.username}]] <br/>
First Name: [[${account.firstName}]] <br/>
Last Name: [[${account.surname}]] <br/>
</body>
</html>
PasswordResetController.java
@RequestMapping(value= "/user/new_password", method = RequestMethod.POST)
public String saveNewPassword(@RequestParam(value="new_password",required=false) String password, @RequestParam(value="hash") String hash, Model model)
{
//some codes to check hash
AccountInfo account = accountInfoService.getAccount(hash);
model.addAttribute("account", account);
return "/successPwd";
}
我得到的是这样的:
Password Changed
Your password has been changed. Your account information is below.
Username: [[${account.username}]]
First Name: [[${account.firstName}]]
Last Name: [[${account.surname}]]
Thymeleaf没有转换到正确的值,很可能我错过了非常基本的东西。
答案 0 :(得分:1)
在这种情况下,您应该使用th:text
。例如,Username: <p th:text=${account.username}>Username will be rendered here</p>
。请注意,p
标记内的文字不会显示。
请点击此处了解详情:Standard thymeleaf syntax
答案 1 :(得分:0)
如果要摆脱“笨拙”的Html标签,可以执行以下操作。
<span th:text="${account.username}" th:remove="tag">userName</span>