springboot请求后缀匹配 spring boot 怎样请求后缀匹配

软件发布|下载排行|最新软件

当前位置:首页IT学院IT技术

springboot请求后缀匹配 spring boot 怎样请求后缀匹配

xutatu   2021-09-29 我要评论
想了解spring boot 怎样请求后缀匹配的相关内容吗,xutatu在本文为您仔细讲解springboot请求后缀匹配的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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

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

Copyright 2022 版权所有 软件发布 访问手机版

声明:所有软件和文章来自软件开发商或者作者 如有异议 请与本站联系 联系我们