Skip to content

Commit

Permalink
feat: close #46, close #47
Browse files Browse the repository at this point in the history
  • Loading branch information
hsiong committed Apr 28, 2024
1 parent 864f9f4 commit d738dcd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>tech.ynfy</groupId>
<artifactId>ynfy-tool-httpconnect</artifactId>
<name>${project.groupId}:${project.artifactId}</name>
<version>1.1.9</version>
<version>1.1.10</version>
<description>A Http Util for Java</description>
<url>https://github.com/ynfy-tech/ynfy-tool-httpconnect</url>

Expand Down
13 changes: 12 additions & 1 deletion src/main/java/http/InitUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,9 @@ protected <T> String appendGetUrlParam(String url, T paramObj) {
if (String.class.equals(paramObj.getClass())) {
throw new IllegalArgumentException("Param can't be string! ");
}
urlNameString.append("?");

urlNameString.append(url.contains("?") ? "&" : "?"); // 使用三元运算符来决定是追加 '&' 还是 '?'

Class c = paramObj.getClass();
Field[] fields = c.getDeclaredFields();
for (Field field : fields) {
Expand All @@ -195,6 +197,15 @@ protected <T> String appendGetUrlParam(String url, T paramObj) {
if (filedValue instanceof Collection) {
Collection collection = (Collection) filedValue;
for (Object s : collection) {

if (s == null) {
continue;
}

if (!String.class.equals(s.getClass())) {
throw new IllegalArgumentException("List param should be string! ");
}

String filedValueStr = URLEncoder.encode((String) s, StandardCharsets.UTF_8);
urlNameString.append(fieldName).append("=").append(filedValueStr).append("&");
}
Expand Down

0 comments on commit d738dcd

Please sign in to comment.