首页 > 其他分享 >springboot如何处理矩阵参数类型的url

springboot如何处理矩阵参数类型的url

时间:2022-10-15 16:13:13浏览次数:63  
标签:map springboot url brand 矩阵 param low urlPathHelper

矩阵参数类型的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;

    }

结果图如下:

标签:map,springboot,url,brand,矩阵,param,low,urlPathHelper
From: https://www.cnblogs.com/wiseleer/p/16794372.html

相关文章