I have added Thymeleaf to my Spring Boot project.
I have created a HTML file in /resources/templates/index.html
I have added a method to my @RestController:
@RequestMapping("/")
public String index(Model model, OAuth2Authentication authentication) {
// irreveland code here
return "index";
}
It seems that this method kinda works, but instead of redirecting me to http://localhost:8080/templates/index.html
I have a white page with a word "index" on it (no html in sources, just the word index )
I have tried to put the index.html page to /resources/static and /resources for test purposes - no effort.
What could go wrong here?
You annotated your controller with @RestController
, which means that all return values are treated as response bodies ( @ResponseBody
). That means that your string "index"
is treated as such, and not as a view.
In order to use the MVC approach, where "index"
refers to a view called index.html
, you should use the @Controller
annotation.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.