0
点赞
收藏
分享

微信扫一扫

接口地址忽略大小写

最近在重写一个项目的接口,写完后运行测试发现接口存在大小写敏感的情况,但是我又找不到原因出在哪里,只能写一个配置类,通过实现WebMvcConfigurer接口的configurePathMatch方法,将AntPathMatcher的实例设置为路径匹配器,并将其设置为不区分大小写。这样,当请求的接口路径与定义的路径因为大小写问题不完全匹配时,仍然可以进行匹配。

配置类如下

import org.springframework.context.annotation.Configuration;
import org.springframework.util.AntPathMatcher;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * MVC配置类
 *
 */
@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

   /**
    * 接口地址忽略大小写
    * @param configurer
    */
   @Override
   public void configurePathMatch(PathMatchConfigurer configurer) {
      AntPathMatcher matcher = new AntPathMatcher();
      matcher.setCaseSensitive(false);
      configurer.setPathMatcher(matcher);
   }

}

举报

相关推荐

0 条评论