|
|
@@ -19,6 +19,7 @@ import com.alibaba.fastjson.annotation.JSONField;
|
|
|
import com.alibaba.fastjson.parser.Feature;
|
|
|
import com.alibaba.fastjson.parser.ParserConfig;
|
|
|
import com.alibaba.fastjson.util.TypeUtils;
|
|
|
+import common.BaseClass;
|
|
|
import common.YosException;
|
|
|
import common.data.Row;
|
|
|
import common.data.Rows;
|
|
|
@@ -31,6 +32,8 @@ import java.lang.reflect.Method;
|
|
|
import java.lang.reflect.Type;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.math.BigInteger;
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
import static com.alibaba.fastjson.util.TypeUtils.*;
|
|
|
@@ -256,13 +259,15 @@ public class JSONObject extends JSON implements Map<String, Object>, Cloneable,
|
|
|
}
|
|
|
|
|
|
public Long getLong(String key) throws YosException {
|
|
|
- fieldContainsCheck(key, "Long");
|
|
|
- Object value = get(key);
|
|
|
-
|
|
|
- return castToLong(value);
|
|
|
+ if (BaseClass.isTableUniqueColumnName(key)) {
|
|
|
+ return getLongValue(key, -1L);
|
|
|
+ } else {
|
|
|
+ fieldContainsCheck(key, "Long");
|
|
|
+ Object value = get(key);
|
|
|
+ return castToLong(value);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public long getLongValue(String key) {
|
|
|
Object value = get(key);
|
|
|
|
|
|
@@ -314,7 +319,6 @@ public class JSONObject extends JSON implements Map<String, Object>, Cloneable,
|
|
|
Object value = get(key);
|
|
|
|
|
|
Double doubleValue = castToDouble(value);
|
|
|
-
|
|
|
if (doubleValue == null) {
|
|
|
return 0D;
|
|
|
}
|
|
|
@@ -364,11 +368,36 @@ public class JSONObject extends JSON implements Map<String, Object>, Cloneable,
|
|
|
|
|
|
public String getStringValue(String key, boolean Keepspecialcharacters, String defValue) {
|
|
|
Object value = get(key);
|
|
|
- if (value == null||value.toString().isEmpty()) {
|
|
|
+ if (value == null || value.toString().isEmpty()) {
|
|
|
return defValue;
|
|
|
}
|
|
|
if (!Keepspecialcharacters) {
|
|
|
value = value.toString().replaceAll("([';])+|(--)+", "");//去除特殊字符,防止sql注入
|
|
|
+ } else {
|
|
|
+ value = value.toString().replace("'", "\\'");
|
|
|
+ }
|
|
|
+ return value.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 验证是否为时间格式
|
|
|
+ *
|
|
|
+ * @param key
|
|
|
+ * @param pattern
|
|
|
+ * @param defValue
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public String getStringValueForDate(String key, String pattern, String defValue) {
|
|
|
+ Object value = get(key);
|
|
|
+ if (value == null || value.toString().isEmpty()) {
|
|
|
+ return defValue;
|
|
|
+ }
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat(pattern);
|
|
|
+ try {
|
|
|
+ sdf.parse(value.toString());
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ return defValue;
|
|
|
}
|
|
|
return value.toString();
|
|
|
}
|
|
|
@@ -380,6 +409,8 @@ public class JSONObject extends JSON implements Map<String, Object>, Cloneable,
|
|
|
}
|
|
|
if (!Keepspecialcharacters) {
|
|
|
value = value.toString().replaceAll("([';])+|(--)+", "");//去除特殊字符,防止sql注入
|
|
|
+ } else {
|
|
|
+ value = value.toString().replace("'", "\\'");
|
|
|
}
|
|
|
return value.toString();
|
|
|
}
|
|
|
@@ -397,7 +428,6 @@ public class JSONObject extends JSON implements Map<String, Object>, Cloneable,
|
|
|
if (!Keepspecialcharacters) {
|
|
|
value = value.toString().replaceAll("([';])+|(--)+", "");//去除特殊字符,防止sql注入
|
|
|
} else {
|
|
|
- // value = value.toString().replace("'", "''");
|
|
|
value = value.toString().replace("'", "\\'");
|
|
|
}
|
|
|
return value.toString();
|