spring boot 请求后缀匹配
spring boot 项目中添加这个类
可以实现url不同后缀区分了
复制代码
1
2
3
4
5
6
7
8
9public class UrlMatchConfig extends WebMvcConfigurationSupport { @Override public void configurePathMatch(PathMatchConfigurer configurer) { //setUseSuffixPatternMatch 后缀模式匹配 configurer.setUseSuffixPatternMatch(true); //setUseTrailingSlashMatch 自动后缀路径模式匹配 configurer.setUseTrailingSlashMatch(true); } }
spring boot 开启后缀匹配模式
项目原有Java配置为继承 WebMvcConfigurationSupport而
复制代码
1WebMvcConfigurationSupport#requestMappingHandlerMapping
默认开启后缀匹配
复制代码
1mapping.setUseSuffixPatternMatch(useSuffixPatternMatch)
后来项目框架调整,有位同学改为 implements WebMvcConfigurer,但该类没有缺省配置,故开启
复制代码
1
2
3
4@Override public void configurePathMatch(PathMatchConfigurer configurer) { configurer.setUseSuffixPatternMatch(true); }
开启后缀匹配后
路径/参数有[.] 符号被过滤掉时配置 [:.+]
复制代码
1@GetMapping(value = "/path/{param:.+}")
other:
application.xml 配置文件可配置为 spring.mvc.pathmatch.use-suffix-pattern=true
以上为个人经验,希望能给大家一个参考,也希望大家多多支持靠谱客。
最后
以上就是健壮黄蜂最近收集整理的关于spring boot 如何请求后缀匹配的全部内容,更多相关spring内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复