导读 这篇文章主要介绍了spring boot 请求后缀匹配的操作,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教

spring boot 请求后缀匹配
spring boot 项目中添加这个类

可以实现url不同后缀区分了

public class UrlMatchConfig extends WebMvcConfigurationSupport {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        //setUseSuffixPatternMatch 后缀模式匹配
        configurer.setUseSuffixPatternMatch(true);
        //setUseTrailingSlashMatch 自动后缀路径模式匹配
        configurer.setUseTrailingSlashMatch(true);
    }
}
spring boot 开启后缀匹配模式
项目原有Java配置为继承 WebMvcConfigurationSupport
WebMvcConfigurationSupport#requestMappingHandlerMapping

默认开启后缀匹配

mapping.setUseSuffixPatternMatch(useSuffixPatternMatch)

后来项目框架调整,有位同学改为 implements WebMvcConfigurer,但该类没有缺省配置,故开启

@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
    configurer.setUseSuffixPatternMatch(true);
}
开启后缀匹配后

路径/参数有[.] 符号被过滤掉时配置 [:.+]

@GetMapping(value = "/path/{param:.+}")

other:

application.xml 配置文件可配置为 spring.mvc.pathmatch.use-suffix-pattern=true

以上为个人经验,希望能给大家一个参考

原文来自:https://www.jb51.net/article/224378.htm

本文地址:https://www.linuxprobe.com/spring-boot-url.html编辑:xiangping wu,审核员:逄增宝

Linux命令大全:https://www.linuxcool.com/

Linux系统大全:https://www.linuxdown.com/

红帽认证RHCE考试心得:https://www.rhce.net/