How can I solve the problem with Spring Boot and Thymeleaf?

Viewed 70

I started developing my spring boot application and faced a problem with thymeleaf.

TaskController.java

@Controller
public class TaskController {

    @GetMapping({"/index"})
    public String index(Model model) {
        model.addAttribute("name", "Augustine");
        return "index";
    }

}

index.html

<!DOCTYPE HTML>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Spring Boot Thymeleaf Application</title>
</head>
<body>
<h1>Welcome to Thymeleaf Spring Boot</h1>
<h2>
    <span>Hello, <th:block th:text="${name}">[name]</th:block></span>
</h2>
</body>
</html>

application.properties

# setup server port
server.port=8080
# setup a default suffix
spring.mvc.view.suffix=.html
# setup thymeleaf
spring.thymeleaf.prefix=classpath:/templates/

A part of pom.xml

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-thymeleaf</artifactId>
        </dependency>

Result https://i.stack.imgur.com/VrHzY.png

Here is folders and files structure https://i.stack.imgur.com/YWJ3i.png

If I put index.html into resources/templates/, I have an issue following https://i.stack.imgur.com/iZroA.png

So how could I solve this problem? Thank you for your help!

0 Answers
Related