如何在spring-boot中提供静态html内容页面
我通过spring-boot
嵌入式tomcat,并希望将一个静态index.html
页面作为正在运行的应用程序的一部分。
但以下不起作用:
@SpringBootApplication public class HMyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } } @RestController public class HomeContoller { @RequestMapping("/") public String index() { return "index"; } } src/main/resources/static/index.html
结果:当我调用localhost:8080
,我只看到“index”这个词,但不是我的html页面。 为什么?
我的错:我有一个带有@EnableWebMvc
注释的附加类。 这在某种程度上搞砸了spring-boot自动配置。 我删除了它,现在它返回index.html
。
对我来说这很有效,我相信有更好的方法(比如没有.html)。
@RequestMapping("/") public String index() { return "index.html"; }