Java Thymeleaf未重定向到index.html

Java Thymeleaf未重定向到index.html,java,spring,spring-boot,thymeleaf,Java,Spring,Spring Boot,Thymeleaf,我已将Thymeleaf添加到我的Spring Boot项目中 我在/resources/templates/index.HTML 我在@RestController中添加了一个方法: @RequestMapping("/") public String index(Model model, OAuth2Authentication authentication) { // irreveland code here return "index"; } 这种方法似乎有点有效,但不

我已将Thymeleaf添加到我的Spring Boot项目中

我在
/resources/templates/index.HTML

我在@RestController中添加了一个方法:

@RequestMapping("/")
public String index(Model model, OAuth2Authentication authentication) {
    // irreveland code here
    return "index";
}
这种方法似乎有点有效,但不是将我重定向到
http://localhost:8080/templates/index.html
我有一个白色页面,上面有一个单词“index”(源代码中没有html,只有单词index

出于测试目的,我已尝试将index.html页面放置到/resources/static和/resources中-不费吹灰之力


这里会出什么问题?

您用
@RestController
注释了控制器,这意味着所有返回值都被视为响应体(
@ResponseBody
)。这意味着您的字符串
“index”
被视为这样,而不是视图


为了使用MVC方法,
“index”
引用了一个名为
index.html
的视图,您应该使用
@Controller
注释。

就是这样。。。我在用RestController测试我的API以与postman一起玩,但我忘了更改它。在上述情况下,控制器注释的工作方式类似于字符,您只能在浏览器中看到“index”一词,因为
@RestContoller
@Controller
@ResponseBody
的组合。这只是返回对象和对象数据,这些数据作为文本直接写入HTTP响应。在您的例子中,您可能正在创建一个地图,然后提供用于显示结果的视图。这需要
@Controller
注释。欲了解更多信息,请阅读