矩阵参数类型的url如何处理
首先要开启这个功能
在webconfig类中创建Webconfigurer类 并且设置 urlPathHelper类中的removeSemicolonContent 为false
@Bean
public WebMvcConfigurer webMvcConfigurer(){
return new WebMvcConfigurer() {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper urlPathHelper = new UrlPathHelper();
urlPathHelper.setRemoveSemicolonContent(false);
configurer.setUrlPathHelper(urlPathHelper);
}
};
}
下面测试类
/**
* url: http://localhost:8080/cars/sell;low=34;brand=byd,audi,yd
* @param low
* @param brand
* @param PATH
* @return map
*/
@GetMapping("/cars/{path}")
public Map carsSell(@MatrixVariable("low") Integer low,
@MatrixVariable("brand") List<String> brand,
@PathVariable("path")String PATH){
Map<String,Object> map = new HashMap<>();
map.put("low",low);
map.put("brand",brand);
map.put("path",PATH);
return map;
}