admin
2021-07-30 19533a17aa55fafc70d0a385928e785cb50e1ebc
src/main/java/com/yeshi/buwan/util/StringUtil.java
@@ -9,7 +9,9 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.DateFormat;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -55,6 +57,18 @@
        String st = "";
        for (int i = 0; i < srcList.size(); i++) {
            st += srcList.get(i) + seperate;
        }
        if (st.endsWith(seperate)) {
            st = st.substring(0, st.length() - seperate.length());
        }
        return st;
    }
    public static String join(Collection srcList, String seperate) {
        String st = "";
        for (Iterator<String> its = srcList.iterator(); its.hasNext(); ) {
            st += its.next() + seperate;
        }
        if (st.endsWith(seperate)) {
            st = st.substring(0, st.length() - seperate.length());
@@ -174,15 +188,15 @@
        } else {
            Gson gson = new GsonBuilder().enableComplexMapKeySerialization().excludeFieldsWithoutExposeAnnotation()
                    .setDateFormat(DateFormat.LONG).registerTypeAdapter(Date.class, new JsonSerializer<Date>() {
                @Override
                public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                    if (value == null) {
                        return new JsonPrimitive("0");
                    } else {
                        return new JsonPrimitive(value.getTime());
                    }
                }
            }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写
                        @Override
                        public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) {
                            if (value == null) {
                                return new JsonPrimitive("0");
                            } else {
                                return new JsonPrimitive(value.getTime());
                            }
                        }
                    }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写
                    .setPrettyPrinting().setVersion(1.0).create();
            String st = gson.toJson(o);
            return Utils.JsonFilter(st);