首页 > 编程语言 > 详细

spring boot 2.x 接口路径后缀匹配

时间:2021-08-18 15:33:33      阅读:26      评论:0      收藏:0      [点我收藏+]

实现RequestMapping("/test")可以跟/test匹配,也可以跟/test.json /test.aa ......

spring boot 1.x 是支持这种匹配的,但是项目升级 spring boot 2.x不支持后缀匹配了

修改:

代码中加过滤器,开启后缀匹配

实现:

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
 
/**
 * 过滤器 spring boot 2.x 开启路径后缀匹配
 * @author yang.fu
 * @Date 2021年8月18日
 *
 */
@Configuration
public class MyWebMvcConfigurer implements  WebMvcConfigurer  {
 
	@Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        //开启路径后缀匹配
        configurer.setUseRegisteredSuffixPatternMatch(true);
    }
}

spring boot 2.x 接口路径后缀匹配

原文:https://www.cnblogs.com/f9264/p/15156381.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!