diff --git a/pom.xml b/pom.xml
index 5f7d533..42a67ff 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.imyeyu.network
timi-network
- 0.0.2
+ 0.0.3
jar
diff --git a/src/main/java/com/imyeyu/network/ArgMap.java b/src/main/java/com/imyeyu/network/ArgMap.java
index 455c4a4..bbb8631 100644
--- a/src/main/java/com/imyeyu/network/ArgMap.java
+++ b/src/main/java/com/imyeyu/network/ArgMap.java
@@ -35,6 +35,36 @@ public class ArgMap extends HashMap {
}
public String toURL(String url) {
- return url + "?" + toURL();
+ StringBuilder sb = new StringBuilder(url);
+ if (url.contains("?")) {
+ if (!url.endsWith("?") && !url.endsWith("&")) {
+ sb.append('&');
+ }
+ sb.append(toURL());
+ return sb.toString();
+ } else {
+ return url + "?" + toURL();
+ }
+ }
+
+ public static ArgMap of(K key, V value) {
+ ArgMap map = new ArgMap<>();
+ map.put(key, value);
+ return map;
+ }
+
+ public static ArgMap of(K key1, V value1, K key2, V value2) {
+ ArgMap map = new ArgMap<>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ return map;
+ }
+
+ public static ArgMap of(K key1, V value1, K key2, V value2, K key3, V value3) {
+ ArgMap map = new ArgMap<>();
+ map.put(key1, value1);
+ map.put(key2, value2);
+ map.put(key3, value3);
+ return map;
}
}
diff --git a/src/test/java/com/imyeyu/network/test/ArgMapTest.java b/src/test/java/com/imyeyu/network/test/ArgMapTest.java
new file mode 100644
index 0000000..6ff5bbe
--- /dev/null
+++ b/src/test/java/com/imyeyu/network/test/ArgMapTest.java
@@ -0,0 +1,27 @@
+package com.imyeyu.network.test;
+
+import com.imyeyu.network.ArgMap;
+import org.junit.Test;
+
+/**
+ *
+ *
+ * @author 夜雨
+ * @since 2026-02-10 12:45
+ */
+public class ArgMapTest {
+
+ @Test
+ public void toURLTest() {
+ assert ArgMap.of("key", "value").toURL("/detail").equals("/detail?key=value");
+ assert ArgMap.of("key", "value").toURL("/detail?").equals("/detail?key=value");
+ assert ArgMap.of("key", "value").toURL("/detail?id=123").equals("/detail?id=123&key=value");
+ assert ArgMap.of("key", "value").toURL("/detail?id=123&").equals("/detail?id=123&key=value");
+ assert ArgMap.of("key", "value").toURL("http://localhost/detail").equals("http://localhost/detail?key=value");
+ assert ArgMap.of("key", "value").toURL("http://localhost/detail?").equals("http://localhost/detail?key=value");
+
+ String uri = ArgMap.of("key", "value").toURL("/detail?id=123");
+ String url = ArgMap.of("newKey", "newValue").toURL("http://localhost/test" + uri);
+ assert url.equals("http://localhost/test/detail?id=123&key=value&newKey=newValue");
+ }
+}