好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

spring boot 如何请求后缀匹配

spring boot 请求后缀匹配

spring boot 项目中添加这个类

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

?

1

2

3

4

5

6

7

8

9

public class UrlMatchConfig extends WebMvcConfigurationSupport {

     @Override

     public void configurePathMatch(PathMatchConfigurer configurer) {

         //setUseSuffixPatternMatch 后缀模式匹配

         configurer.setUseSuffixPatternMatch( true );

         //setUseTrailingSlashMatch 自动后缀路径模式匹配

         configurer.setUseTrailingSlashMatch( true );

     }

}

spring boot 开启后缀匹配模式

项目原有Java配置为继承 WebMvcConfigurationSupport而

?

1

WebMvcConfigurationSupport#requestMappingHandlerMapping

默认开启后缀匹配

?

1

mapping.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

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

原文链接:https://blog.csdn.net/weixin_42115175/article/details/80210400

查看更多关于spring boot 如何请求后缀匹配的详细内容...

  阅读:40次