From a5106b61fc8d50609385e1e6d25664a10a11ccf9 Mon Sep 17 00:00:00 2001
From: wuxw <928255095@qq.com>
Date: 星期四, 19 十月 2023 18:38:19 +0800
Subject: [PATCH] 优化代码
---
java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java | 31 ++++++++++++++++++++++++++-----
1 files changed, 26 insertions(+), 5 deletions(-)
diff --git a/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java b/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
old mode 100644
new mode 100755
index 1dfd8fd..52e2ef7
--- a/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
+++ b/java110-utils/src/main/java/com/java110/utils/util/Java110Converter.java
@@ -17,7 +17,7 @@
* add by wuxw 2020/1/28
**/
public class Java110Converter implements Converter {
- static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
@Override
public Object convert(Object value, Class target, Object context) {
@@ -27,6 +27,8 @@
public static Object getValue(Object value, Class target) {
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+
if (value == null) {
return value;
}
@@ -34,13 +36,14 @@
if (value instanceof String && target == Date.class) {
String date = (String) value;
Date newDate = null;
+ SimpleDateFormat strdf = null;
if (date.contains(":")) {
- //sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
+ strdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
} else {
- sdf = new SimpleDateFormat("yyyy-MM-dd");
+ strdf = new SimpleDateFormat("yyyy-MM-dd");
}
try {
- newDate = sdf.parse(date);
+ newDate = strdf.parse(date);
} catch (ParseException e) {
e.printStackTrace();
}
@@ -75,7 +78,7 @@
return newDate;
}
- if (value instanceof BigDecimal) {
+ if (value instanceof BigDecimal && target == String.class) {
BigDecimal bd = (BigDecimal) value;
return bd.toPlainString();
}
@@ -84,14 +87,23 @@
}
if (target == int.class || target == Integer.class) {
+ if(StringUtil.isNullOrNone(value)){
+ return 0;
+ }
return Integer.parseInt(String.valueOf(value));
}
if (target == long.class || target == Long.class) {
+ if(StringUtil.isNullOrNone(value)){
+ return 0;
+ }
return Long.parseLong(String.valueOf(value));
}
if (target == double.class || target == Double.class) {
+ if(StringUtil.isNullOrNone(value)){
+ return 0;
+ }
return Double.parseDouble(String.valueOf(value));
}
@@ -99,6 +111,15 @@
return String.valueOf(value).split(",");
}
+ //1.0 String 杞� Date
+ if (value instanceof String && target == boolean.class) {
+ String bl = (String) value;
+ if ("true".equals(bl)) {
+ return true;
+ }
+ return false;
+ }
+
return value;
}
}
--
Gitblit v1.8.0