我是 Thymeleaf 的新手。我有一个 spring-boot 项目,我试图在其中显示一些已从 spring Controller 设置的属性值。
@Controller
public class HomeController {
@RequestMapping(path = "/info", method = RequestMethod.GET)
public String info(Model model) {
model.addAttribute("message", "Thymeleaf");
return "info";
}
}
请在下面找到我的 info.html 页面:
<!DOCTYPE html>
<html xmlns:thm="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Info</title>
</head>
<body>
<h1 thm:text="${message}"></h1>
</body>
</html>
请在下面找到我的 pom.xml 文件 [仅依赖项]
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-thymeleaf -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
</dependencies>
我知道 stackoverflow 上很少有关于这个主题的帖子,我已经浏览过其中的一些帖子,如下所示:
我根据 stackoverflow 博客的建议相应地修改了我的 html 页面。但问题仍然存在。
我的网页根本没有重新渲染 Thymeleaf 文本。 谁能弄清楚确切的问题吗?
最佳答案
thm
不是 Thymeleaf 中的有效前缀,请使用 <h1 th:text="${message}"></h1>
相反。
关于java - Thymeleaf 在 Spring Boot 项目中不显示值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49210589/