Spring Boot 2.x实战45 - Spring Web MVC 17 - Web MVC配置(路径匹配和内容协商-PathMatchConfigurer)

3.9 路径匹配和内容协商Spring MVC中可以通过重载WebMvcConfigurer接口的configurePathMatch方法来设置路径匹配。Spring MVC为我们提供了PathMatchConfigurer来进行路径匹配配置。 public void configurePathMatch(PathMatchConfigurer configurer) { }3.9.1 后缀匹配使用PathMatchConfigurer.setUseSuffixPatternMatc
摘要由CSDN通过智能技术生成
3.9 路径匹配和内容协商

Spring MVC中可以通过重载WebMvcConfigurer接口的configurePathMatch方法来设置路径匹配。Spring MVC为我们提供了PathMatchConfigurer来进行路径匹配配置。

    public void configurePathMatch(PathMatchConfigurer configurer) {
   
    }
3.9.1 后缀匹配

使用PathMatchConfigurer.setUseSuffixPatternMatch(Boolean suffixPatternMatch)设置是否使用后缀匹配。若设置为true则路径/xx/xx.*是等效的,Spring Boot下默认是false

configurer.setUseSuffixPatternMatch(true);

在这里插入图片描述
我们还可以在外部配置application.yml快捷配置与同样的效果:

spring.mvc.pathmatch.use-suffix-pattern: true //Spring Boot默认是false
3.9.2 斜线匹配

使用PathMatchConfigurer.setUseTrailingSlashMatch(Boolean trailingSlashMatch)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值