Spring Boot - 如何为指定根目录中的多个路由提供一个静态 html 文件 [英] Spring Boot - how to serve one static html file for multiple routes in specified root

查看:39
本文介绍了Spring Boot - 如何为指定根目录中的多个路由提供一个静态 html 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要为指定根 (例如'/main/\**').我尝试使用 @RequestMapping("/main/**") 注释控制器方法,但它仅适用于 '/main' 路由,不适用于 '<代码>/main/foo'、'/main/foo/bar' 等...

I need to serve static html file (/src/main/resources/static/folder/index.html) for all routes in specified root (as example '/main/\**'). I've tried to annotate controller method with @RequestMapping("/main/**"), but it works only for '/main' route, not for '/main/foo', '/main/foo/bar', etc...

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

So, how i can do this in spring boot?

推荐答案

我找到了这个解决方案:

I found this solution:

// 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";
    }
}

这篇关于Spring Boot - 如何为指定根目录中的多个路由提供一个静态 html 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆