Spring Boot - 如何为指定根目录中的多个路由提供一个静态 html 文件

Ant*_*ton 6 java spring spring-mvc spring-boot

我需要为指定 root 中的所有路由提供静态html文件。我试图用注释控制器的方法,但它仅适用于路由,而不是' ,等...(/src/main/resources/static/folder/index.html)(as example '/main/\**')@RequestMapping("/main/**")'/main'/main/foo''/main/foo/bar'

那么,我如何在 Spring Boot 中做到这一点?

Ant*_*ton 6

我找到了这个解决方案:

// application.properties
spring.mvc.view.prefix=/
spring.mvc.view.suffix=.html


// Controller for index.html
@Controller
public class IndexController {

    @RequestMapping({"/login", "/main/**"})
    public String index() {
        return "index";
    }
}
Run Code Online (Sandbox Code Playgroud)