Spring Boot MVC request mapping overrides static resources

淺唱寂寞╮ 提交于 2019-12-11 08:33:16

问题


I want to have rest controller in Spring Boot to handle all requests like this: "/{arg}", EXCEPT "/sitemap.xml". How can I achieve that?


回答1:


You could specify your request mapping on the controller level via regex and exclude some resources (e.g. 'excludeResourceA' and 'excludeResourceB') with:

@RestController
@RequestMapping(value = "/{arg:(?!sitemap.xml|excludeResourceA|excludeResourceB).*$}")
public class YourRestController {
    // your implementation
}

Of course you can also specify the request mapping on the method level with the same regex relative to your controller path matching and you can pass the argument with @PathVariable("arg") String arg in your method signature to your method body if you need it.



来源:https://stackoverflow.com/questions/41725343/spring-boot-mvc-request-mapping-overrides-static-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!