springboot如何处理矩阵参数类型的url
矩阵参数类型的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;
}
结果图如下:
本文来自博客园,作者:wiselee/,转载请注明原文链接:https://www.cnblogs.com/wiseleer/p/16794372.html