如何将重写规则添加到 spring boot 2.3.1
How to add rewrite rule to spring boot 2.3.1
我有一个 Spring 基于 this example 的启动应用程序。
现在的问题是当用户访问根 URL.
时,如何向我的应用程序添加重写规则以添加 /index.html
我的意思是当用户访问 http://localhost:8080/my-app
或 http://localhost:8080/my-app/
然后我将他或她重定向到 http://localhost:8080/my-app/index.html
。
我发现了一些东西 ,但不幸的是对我不起作用,而且 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
似乎不再存在于 Spring Boot 2.3.1 中。
我只需要添加一个新的控制器,尽管这个应用程序不使用 MVC,这个控制器会将 /
请求重定向到 /index.html
。
package me.cimply.ask.odata.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class AppController {
@GetMapping("/")
public String index() {
return "redirect:index.html";
}
}
我有一个 Spring 基于 this example 的启动应用程序。
现在的问题是当用户访问根 URL.
时,如何向我的应用程序添加重写规则以添加/index.html
我的意思是当用户访问 http://localhost:8080/my-app
或 http://localhost:8080/my-app/
然后我将他或她重定向到 http://localhost:8080/my-app/index.html
。
我发现了一些东西 org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory
似乎不再存在于 Spring Boot 2.3.1 中。
我只需要添加一个新的控制器,尽管这个应用程序不使用 MVC,这个控制器会将 /
请求重定向到 /index.html
。
package me.cimply.ask.odata.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class AppController {
@GetMapping("/")
public String index() {
return "redirect:index.html";
}
}