feat: 升级1.1.1,解决get传参

This commit is contained in:
wangyu 2023-02-20 14:23:44 +08:00
parent a8f7c6adf4
commit 3f9755df0b
5 changed files with 29 additions and 13 deletions

View File

@ -13,7 +13,7 @@
<groupId>group.flyfish</groupId>
<artifactId>rest-proxy</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
@ -22,7 +22,7 @@
<java.version>1.8</java.version>
<commons-collection.version>4.4</commons-collection.version>
<commons.lang.version>2.6</commons.lang.version>
<sdk.version>1.1.0</sdk.version>
<sdk.version>1.1.1</sdk.version>
</properties>
<packaging>pom</packaging>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>group.flyfish</groupId>
<artifactId>rest-proxy</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -5,7 +5,7 @@
<parent>
<groupId>group.flyfish</groupId>
<artifactId>rest-proxy</artifactId>
<version>1.1.0</version>
<version>1.1.1</version>
</parent>
<modelVersion>4.0.0</modelVersion>

View File

@ -21,7 +21,7 @@ public abstract class AbstractParamResolver {
if (DataUtils.isNotEmpty(builder.getParams())) {
String start = builder.getUrl().contains("?") ? "&" : "?";
String params = builder.getParams().entrySet().stream()
.map(entry -> entry.getKey() + "=" + parseValue(entry.getValue()))
.map(entry -> entry.getKey() + "=" + valueOf(entry.getValue()))
.collect(Collectors.joining("&"));
builder.url(builder.getUrl() + start + params);
}
@ -34,14 +34,10 @@ public abstract class AbstractParamResolver {
* @param value
* @return 结果
*/
private String parseValue(Object value) {
private String valueOf(Object value) {
if (value instanceof String) {
return (String) value;
}
if (value instanceof Iterable) {
Iterable<? extends CharSequence> mapped = DataUtils.cast(value);
return String.join(",", mapped);
}
if (null != value) {
return String.valueOf(value);
}

View File

@ -56,7 +56,7 @@ public class RestParamArgumentResolver implements RestArgumentResolver {
if (context.getMethod().isMergeBody()) {
context.setBody(name, value);
} else {
context.setParam(name, value);
context.setParam(name, parseValue(value));
}
}
}
@ -79,7 +79,7 @@ public class RestParamArgumentResolver implements RestArgumentResolver {
Map<String, Object> values = DataUtils.cast(value);
values.forEach((k, v) -> {
if (null != v) {
context.setParam(k, String.valueOf(v));
context.setParam(k, parseValue(v));
}
});
} else {
@ -95,10 +95,30 @@ public class RestParamArgumentResolver implements RestArgumentResolver {
log.error("【Rest客户端】尝试解析参数时发生异常!获取bean的属性表失败!{}", e.getMessage(), e);
}
if (null != v) {
context.setParam(propertyDescriptor.getName(), String.valueOf(v));
context.setParam(propertyDescriptor.getName(), parseValue(v));
}
}
}
}
}
/**
* 解析值
*
* @param value
* @return 结果
*/
private String parseValue(Object value) {
if (value instanceof String) {
return (String) value;
}
if (value instanceof Iterable) {
Iterable<? extends CharSequence> mapped = DataUtils.cast(value);
return String.join(",", mapped);
}
if (null != value) {
return String.valueOf(value);
}
return "";
}
}