FeignClient pageable sort 无法desc

客户端:

FeignClient pageable sort 无法desc_第1张图片
image.png

GET http://product/products?search=status%3D%3DON%3Bcategories.id%3D%3Dff8080817495c0cf017495c28b0e0000&page=0&size=12&sort=price&sort=DESC

服务端:

FeignClient pageable sort 无法desc_第2张图片
image.png

问题

在url生成的排序,好像不大对

生产了错误的查询
sort=price&sort=DESC

正确的为
sort=price,DESC

过程

通过跟踪 PageableSpringEncoder 组成查询参数也没啥问题


FeignClient pageable sort 无法desc_第3张图片
image.png

sort=price,DESC 非常的正常,那就代表,在之后给弄坏了

找到发生变化的地方
ReflectiveFeign
this.buildTemplateFromArgs.create(argv)

问题

QueryTemplate

public String expand(Map variables) {
        String name = this.name.expand(variables);
        if (this.pure) {
            return name;
        } else {
            List expanded = new ArrayList();
            Iterator var4 = this.values.iterator();

            while(var4.hasNext()) {
                Template template = (Template)var4.next();
                String result = template.expand(variables);
                if (result != null) {
                    if (result.contains(",")) {
                        expanded.addAll(Arrays.asList(result.split(",")));
                    } else {
                        expanded.add(result);
                    }
                }
            }

            return this.queryString(name, Collections.unmodifiableList(expanded));
        }
    }

解决方法

覆盖 QueryTemplate 类改写expand方法


public String expand(Map variables) {
        String name = this.name.expand(variables);
        if (this.pure) {
            return name;
        } else {
            List expanded = new ArrayList();
            Iterator var4 = this.values.iterator();

            while(var4.hasNext()) {
                Template template = (Template)var4.next();
                String result = template.expand(variables);
                if (result != null) {
//                    if (result.contains(",")) {
//                        expanded.addAll(Arrays.asList(result.split(",")));
//                    } else {
                        expanded.add(result);
//                    }
                }
            }

            return this.queryString(name, Collections.unmodifiableList(expanded));
        }
    }

参考

google到类型问题 的人
https://www.gitmemory.com/issue/spring-cloud/spring-cloud-openfeign/146/533275272

你可能感兴趣的:(FeignClient pageable sort 无法desc)