Home > Mobile >  thymeleaf dependency in springboot not working
thymeleaf dependency in springboot not working

Time:04-09

I'm starting with a project in springboot, and I've an error that I've never seen before and I have not been able to solve it, it is with the thymeleaf dependency is not working, im working with intellij idea community edition. it dont let me use the th:text, please see the image. i have deleted the project and redownloaded several times, delete the m2 folder and nothing works for me.

this is my controller:

@Controller
public class IndexController {

@GetMapping(value = "/index")
public String index(Model model){
    model.addAttribute("titulo", "nombre");
    return "index";
}
}

this is de index.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>th:text="${titulo}"</title>
</head>
<body>

</body>
</html>

when i run the code localhost don't show me the correct information, I already have the dependency installed.

enter image description here

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

enter image description here

CodePudding user response:

Your template is being served as a static resource. The controller has a mapping for /index but you have accessed http://localhost:8080. Either change the mapping to @GetMapping("/") or access http://local host:8080/index. You should also check the location of index.html in your project. It should be in src/main/resources/templates.

  • Related