Java SpringRESTAPI和无后缀的静态web内容访问

Java SpringRESTAPI和无后缀的静态web内容访问,java,html,spring,spring-mvc,resources,Java,Html,Spring,Spring Mvc,Resources,假设我有一个名为application的springrestapi,它的请求映射到/API。这意味着我调用例如GET方法来获取用户列表: localhost:8080/application/api/users 工作顺利。我的目标是使简单的静态html文件与此API一起能够相互引用。我需要找到index.html文件并将其作为主页 localhost:8080/application/ 它使用以下命令正确显示我的index.html: @RequestMapping(value = "/",

假设我有一个名为
application
的springrestapi,它的请求映射到
/API
。这意味着我调用例如
GET
方法来获取用户列表:

localhost:8080/application/api/users
工作顺利。我的目标是使简单的静态html文件与此API一起能够相互引用。我需要找到
index.html
文件并将其作为主页

localhost:8080/application/
它使用以下命令正确显示我的
index.html

@RequestMapping(value = "/", method = RequestMethod.GET)
public String homePage(ModelMap model) {
    return "home";
}

我要做的是在同一文件夹
index2.html
index3.html
中的另一个文件上导航
,而不需要明确地写后缀
html
。我试图实现访问网页的功能,如

localhost:8080/application/index2
不使用另一个@RequestMapping(第一个映射主页的除外)

还有一个问题,有没有办法在路径导航中“跳过”文件夹?为了清楚起见,我想把这些html文件放到
webapp/static
文件夹中,但是我必须像这样访问它们

localhost:8080/application/static/...
我很快就尝试了一些关于Spring资源映射的教程,但是没有一个介绍了任何类似问题的解决方案。我不使用弹簧靴

谢谢你的帮助


很快:

如何通过以下方式访问-->中的文件:


你可以用这样的东西

@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("login");
    registry.addViewController("/welcome").setViewName("welcome");
    registry.addViewController("/about").setViewName("about");
    registry.addViewController("/contact").setViewName("contact");
}

其中login映射到login.html,welcome映射到welcome.html。它不需要@RequestMapping,但仍然需要显式映射。

可能重复@AbhijitSarkar Nope,我不使用Spring Boot:)好的,我收回了我的投票,因为我提到的答案是针对Boot的。可能是最好的答案。虽然我似乎无法避免手动解析要查看的特定URL。
webapp/WEB-INF/pages/index.html --> localhost:8080/application
webapp/static/index2.html       --> localhost:8080/application/index2
webapp/static/index3.html       --> localhost:8080/application/index3
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {

@Override
public void addViewControllers(ViewControllerRegistry registry) {
    registry.addViewController("/login").setViewName("login");
    registry.addViewController("/welcome").setViewName("welcome");
    registry.addViewController("/about").setViewName("about");
    registry.addViewController("/contact").setViewName("contact");
}