Skip to content

Commit 6480d73

Browse files
committed
add Param encode
1 parent f974b04 commit 6480d73

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

springboot-starter/pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -64,5 +64,17 @@
6464
</dependency>
6565

6666
</dependencies>
67+
<build>
68+
<plugins>
69+
<plugin>
70+
<groupId>org.apache.maven.plugins</groupId>
71+
<artifactId>maven-compiler-plugin</artifactId>
72+
<configuration>
73+
<source>10</source>
74+
<target>10</target>
75+
</configuration>
76+
</plugin>
77+
</plugins>
78+
</build>
6779

6880
</project>

springboot-starter/src/main/java/com/codingapi/springboot/framework/rest/param/RestParamBuilder.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import org.springframework.util.MultiValueMap;
88

99
import java.beans.PropertyDescriptor;
10+
import java.net.URLEncoder;
11+
import java.nio.charset.StandardCharsets;
1012

1113
public class RestParamBuilder {
1214

@@ -45,10 +47,15 @@ public MultiValueMap<String, String> toFormRequest() {
4547
}
4648

4749
public RestParamBuilder add(String key, Object value) {
50+
return add(key, value,true);
51+
}
52+
53+
public RestParamBuilder add(String key, Object value,boolean encode) {
54+
String stringValue = value.toString();
55+
String encodeValue = encode? URLEncoder.encode(stringValue, StandardCharsets.UTF_8):value.toString();
4856
jsonBody.put(key, value);
49-
mapBody.add(key, value.toString());
57+
mapBody.add(key, encodeValue);
5058
return this;
5159
}
5260

53-
5461
}

0 commit comments

Comments
 (0)