我在com.tuke.doto.Controllers/RootController.java
中有这个:
package com.tuke.doto.Controllers;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
public class RootController {
@RequestMapping("/")
public String root() {
return "frontpage";
}
}
我在 main/resources/static
中有 frontpage.html
(我还尝试将其移至 main/resources/templates
当我在 localhost:8080
上请求时,我看到这个:
HTTP Status [404] – [Not Found]
Type Status Report
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/8.5.15
在我的 jetbrains intellij 控制台中我看到了这个:
javax.servlet.ServletException: Circular view path [error]: would dispatch back to the current handler URL [/error] again. Check your ViewResolver setup! (Hint: This may be the result of an unspecified view, due to default view name generation.)
我还将 server.error.whitelabel.enabled=false
包含到 main/resources/application.properties
问题出在哪里?这不是最简单的例子吗?为什么它不起作用?
编辑也许我应该安装一些依赖项才能使其工作...... 这就是我的 build.gradle 现在的样子:
dependencies {
compile('org.springframework.boot:spring-boot-starter-web')
compile('org.springframework.boot:spring-boot-starter-websocket')
compile("org.springframework.boot:spring-boot-devtools")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
最佳答案
如果你只是使用静态html,你可能不需要像百里香叶这样的模板库。简单返回ModelAndViewObject。将您的 html 放入 src/main/resources/static
示例
@GetMapping("/")
public ModelAndView index() {
return new ModelAndView("frontpage.html");
}
关于java - Spring引导不显示index.html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45249823/