Spring Boot:我可以随传递的url参数一起提供index.html页面吗? 要求:能够读取请求网址参数或请求标头
IndexController
@RestController
public class IndexController {
@RequestMapping(value={"/", "/dashboard"})
public String index(@RequestHeader Map<String, String> headers) {
return "index.html/hi=abc";
}
}
WebApplicationConfig
@Configuration
public class WebApplicationConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/notFound").setViewName("forward:/index.html");
}
@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> containerCustomizer() {
return container -> {
container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,
"/notFound"));
};
}
}
注意: index.html位于正确的位置(资源->公共)。如果没有RestController和RequestMapping,则会显示该页面。我只是不确定如何在索引页中包含url参数