一点点完善
Pair
https://www.jianshu.com/p/a9c92bf8bec5
一个map 拼结参数的工具类:
public final class ParamKit {
public static Map<String, String> of() {
return new HashMap<>();
}
public static Map<String, String> of(String... args) {
List<Pair<String, String>> pairs = new ArrayList<>();
for (int i = 0; i < args.length; i+=2) {
pairs.add(Pair.create(args[i], args[i + 1]));
}
return of(pairs);
}
public static Map<String, String> of(List<Pair<String, String>> kvs) {
Map<String, String> params = new HashMap<>();
if (kvs != null && !kvs.isEmpty()) {
for (Pair<String, String> kv : kvs) {
params.put(kv.first, kv.second);
}
}
return params;
}
public static Map<String, String> of(Pair<String, String>... pairs) {
if (pairs != null) {
return of(Arrays.asList(pairs));
}
return of();
}
public static Map<String, String> page(int page, int limit, Pair<String, String>... pairs) {
Map<String, String> params = of(Pair.create("page", "" + page), Pair.create("limit", "" + limit));
if (pairs != null && pairs.length > 0) {
for (Pair<String, String> kv : pairs) {
params.put(kv.first, kv.second);
}
}
return params;
}
}
使用
ParamKit.page(0,9999,Pair.create("regionCode",regionCode),Pair.create("macCode",macCode))
网友评论