客户端:
image.png服务端:
image.png问题
在url生成的排序,好像不大对
生产了错误的查询
sort=price&sort=DESC
正确的为
sort=price,DESC
过程
通过跟踪 PageableSpringEncoder 组成查询参数也没啥问题
image.png
sort=price,DESC 非常的正常,那就代表,在之后给弄坏了
找到发生变化的地方
ReflectiveFeign
this.buildTemplateFromArgs.create(argv)
问题
QueryTemplate
public String expand(Map<String, ?> variables) {
String name = this.name.expand(variables);
if (this.pure) {
return name;
} else {
List<String> 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<String, ?> variables) {
String name = this.name.expand(variables);
if (this.pure) {
return name;
} else {
List<String> 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
网友评论