Missing matrix variable ‘name‘ for method parameter of type String【解决办法】

今天爱分享给大家带来Missing matrix variable ‘name‘ for method parameter of type String【解决办法】,希望能够帮助到大家。

问题:添加注解 @MatrixVariable 失败
报错信息:Resolved [org.springframework.web.bind.MissingMatrixVariableException: Missing matrix variable ‘name’ for method parameter of type String]
报错截图:

报错原因:SpringBoot 默认是无法使用矩阵变量绑定参数的。需要覆盖 WebMvcConfigurer 中的 configurePathMatch 方法。
解决方案:新增 WebMvcConfig 配置类,实现 WebMvcConfigurer 接口,重写 configurePathMatch 方法。

    @Configuration
    public class WebMvcConfig implements WebMvcConfigurer {
        @Override
        public void configurePathMatch(PathMatchConfigurer configurer) {
            UrlPathHelper urlPathHelper=new UrlPathHelper();
            urlPathHelper.setRemoveSemicolonContent(false);
            configurer.setUrlPathHelper(urlPathHelper);
        }
    }

如果是基于XML的配置,需要加enable-matrix-variables=”true”配置

<mvc:annotation-driven enable-matrix-variables="true" />
原文链接:https://blog.itblood.com/1920.html,转载请注明出处。
0
魅魔契约IIv20.0 AI版[PC+安卓/9.74G/更新]Succubus Contract II [v20.0] [欧美SLG/汉化/动态]
魅魔契约IIv20.0 AI版[PC+安卓/9.74G/更新]Succubus Contract II [v20.0] [欧美SLG/汉化/动态]
5分钟前 有人购买 去瞅瞅看

站点公告

显示验证码
没有账号?注册  忘记密码?