SpringBoot 2.6.2 中UrlPathHelper 中的 removeSemicolonContent 为 true,按理来说应该使得 MatrixVariable 无法使用才对,但是却离奇地可以使用,打印 removeSemicolonContent 的值确实为 true,请各位博友解答?
@GetMapping("/cars/{path}")
public Map<String, Object> carsSell(@MatrixVariable("low") Integer low,
@MatrixVariable("brand") List<String> brand,
@PathVariable("path") String path){
Map<String,Object> map = new HashMap<>();
System.out.println(new UrlPathHelper().shouldRemoveSemicolonContent());
map.put("low",low);
map.put("brand",brand);
map.put("path",path);
return map;
}
springboot 2.6.2 使用的 spring framework 版本是 5.3,5.3 的实现方式和 5.2 的实现方式有一些不同,5.3 版本虽然默认 UrlPathHelper 移除路径中的矩阵变量,但这只会对路径匹配产生影响,路径匹配后会继续使用请求 URI 解析矩阵变量,具体可以参见源码 RequestMappingInfoHandlerMapping#extractMatchDetails(PathPatternsRequestCondition, String, HttpServletRequest)
。