今天爱分享给大家带来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" />
原文链接:http://blog.itblood.com/1920.html,转载请注明出处。

![触手强暴~前 Cranku 冒险家的妻子与触手陷阱1.0[PC+安卓/1.1G] [日系RPG/AI汉化]](/wp-content/uploads/replace/2025/07/19/8e651e1264296aff5a39f6c4de8afe25.webp)