Reputation: 514
I am new to Thymeleaf. I have a spring-boot project where I am trying to display some attributes value which has been set from spring controller.
@Controller
public class HomeController {
@RequestMapping(path = "/info", method = RequestMethod.GET)
public String info(Model model) {
model.addAttribute("message", "Thymeleaf");
return "info";
}
}
Please find below my info.html page:
<!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>
Please find below my pom.xml file [dependencies only]
<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>
I know there are few post in stackoverflow regarding this topic I have already gone through few of them as listed below:
I have accordingly modified my html page as per suggestion from stackoverflow blogs. But still the problem persist.
My web page is not renedering the Thymeleaf text at all. Can anyone figureout the exact issue?
Upvotes: 0
Views: 3428
Reputation: 889
You can first retrieve it from the Model object that you are sending and then you can use it by using th:each
and then th:value
.
<div th:each="message : ${message}">
<h1 th:text="${message}"></h1>
</div>
Upvotes: 0
Reputation: 28269
thm
is not a valid prefix in Thymleaf, use <h1 th:text="${message}"></h1>
instead.
Upvotes: 2