【发布时间】:2016-11-08 08:30:59
【问题描述】:
我正在使用 Spring Boot 并且有一个 html 文件“index.html”,并且我有一个类“Functions”。基本上,我想要发生的是,当函数类运行时,当我转到 localhost:8080 时,html 模板出现在 localhost。 我该怎么做?
这是函数类的一部分:
public class Functions{
@RequestMapping("/")
public void getHomepage(){
//Return the html-template
}
}
html 文件名为“index.html”,位于 src/main/resources/static 文件夹中。
谢谢!
【问题讨论】:
-
将
return "index";放入getHomepage()方法的主体中。请参阅此Spring Web MVC Getting Started 教程。模板应位于src/main/resources/templates而不是src/main/resources/static。 -
非常感谢!我现在就试试
-
@Jesper 是对的。我根据这个教程创建了一个项目,非常有帮助:springframework.guru/…
-
请注意,您必须更改返回类型。
标签: java html spring spring-mvc