Reputation: 89
I tested Thymeleaf and I have a problem, because when I go to localhost and see my html view, dont see my "Test" value, which should be display on the website. This is my code:
@Controller
public class DisplayData {
@RequestMapping("/display")
public String display(Model model){
model.addAttribute("now", "Test");
return "index.html";
}
}
html view:
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset=”utf-8″>
<title>Hello World</title>
</head>
<body>
<h1>Hello World</h1>
Now is: <b th:text="${now}"></b>
</body>
</html>
Path to index.html file is: resources/static/index.html
And localhost view: index.html
Upvotes: 1
Views: 4377
Reputation: 89
I solved my problem. I changed gradle dependencies: It was: compile group: 'org.thymeleaf', name: 'thymeleaf', version: '3.0.7.RELEASE' Now is: compile("org.springframework.boot:spring-boot-starter-thymeleaf")
Upvotes: 0
Reputation: 1964
Three changes are required to make your application up-and-running:
<meta charset=”utf-8″>
is not properly quoted. It should be <meta charset="UTF-8"/>
resources/templates/index.html
return "index";
, since you have annotated your class as @Controller, spring boot will understand that the string returned is the name of the view to be rendered. Then it will automatically check the above-mentioned location to find your view file.You can refer Spring Boot and Template Engines.
Upvotes: 1