gpt4 book ai didi

spring-mvc - 在 Thymeleaf 中显示文本

转载 作者:行者123 更新时间:2023-12-05 08:27:06 26 4
gpt4 key购买 nike

我是 Thymeleaf 的新手。刚刚读过它,现在,我正在尝试在前端使用 Thymeleaf 显示一些文本,在后端从 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 没有转换为正确的值,很可能我在这里错过了一些非常非常基本的东西。

最佳答案

在这种情况下,您应该使用 th:text .例如,Username: <p th:text=${account.username}>Username will be rendered here</p> .注意,里面的文字p标签不会显示。

查看此处了解更多详情:Standard thymeleaf syntax

关于spring-mvc - 在 Thymeleaf 中显示文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46721803/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com