客戶端:
服務(wù)端:
問題
在url生成的排序,好像不大對
生產(chǎn)了錯誤的查詢
sort=price&sort=DESC
正確的為
sort=price,DESC
過程
通過跟蹤 PageableSpringEncoder 組成查詢參數(shù)也沒啥問題
sort=price,DESC 非常的正常磷籍,那就代表纸泡,在之后給弄壞了
找到發(fā)生變化的地方
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