1.3.8 ToUeProperty 增加 ignore

This commit is contained in:
maxf 2019-01-11 13:28:38 +08:00
parent 873bfcbe9f
commit 70c4fb67b1
4 changed files with 21 additions and 5 deletions

View File

@ -1,6 +1,13 @@
yexuejc-base 更新记录 yexuejc-base 更新记录
------------------ ------------------
#### version 1.3.8
**time2019-1-11 13:28:12** <br/>
**branch** master <br/>
**update** <br/>
>1. [ToUeProperty](src/main/java/com/yexuejc/base/util/ToUeProperty.java) 增加 ignore
#
#### version 1.3.7 #### version 1.3.7
**time2019-1-11 10:02:03** <br/> **time2019-1-11 10:02:03** <br/>
**branch** master <br/> **branch** master <br/>

View File

@ -6,7 +6,7 @@
<groupId>top.yexuejc</groupId> <groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId> <artifactId>yexuejc-base</artifactId>
<version>1.3.7</version> <version>1.3.8</version>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<url>https://github.com/yexuejc/yexuejc-base</url> <url>https://github.com/yexuejc/yexuejc-base</url>

View File

@ -109,13 +109,19 @@ public class ObjUtil {
fName = StrUtil.camelToUnderline(f.getName()); fName = StrUtil.camelToUnderline(f.getName());
} }
boolean annotationPresent = f.isAnnotationPresent(ToUeProperty.class); boolean annotationPresent = f.isAnnotationPresent(ToUeProperty.class);
boolean ignore = false;
if (annotationPresent) { if (annotationPresent) {
ToUeProperty annotation = f.getAnnotation(ToUeProperty.class); ToUeProperty annotation = f.getAnnotation(ToUeProperty.class);
ignore = annotation.ignore();
String value = annotation.value(); String value = annotation.value();
if (StrUtil.isNotEmpty(value)) { if (StrUtil.isNotEmpty(value)) {
fName = value; fName = value;
} }
} }
//忽略
if (ignore) {
continue;
}
Object o = f.get(obj); Object o = f.get(obj);
if (null == o || isPrimitive(o) || o instanceof String || o instanceof Enum) { if (null == o || isPrimitive(o) || o instanceof String || o instanceof Enum) {
if (null == o && !putNull) { if (null == o && !putNull) {
@ -175,15 +181,13 @@ public class ObjUtil {
boolean b = obj.getClass().isPrimitive() boolean b = obj.getClass().isPrimitive()
|| obj instanceof Integer || obj instanceof Character || obj instanceof Boolean || obj instanceof Integer || obj instanceof Character || obj instanceof Boolean
|| obj instanceof Number || obj instanceof String || obj instanceof Double || obj instanceof Float || obj instanceof Number || obj instanceof String || obj instanceof Double || obj instanceof Float
|| obj instanceof Short || obj instanceof Long || obj instanceof Byte || obj instanceof Date || obj instanceof Short || obj instanceof Long || obj instanceof Byte || obj instanceof Date;
;
if (b) { if (b) {
return true; return true;
} }
return false; return false;
} }
public static void main(String[] args) { public static void main(String[] args) {
B a = new B(); B a = new B();
a.nameFirst = "张三"; a.nameFirst = "张三";
@ -251,7 +255,6 @@ public class ObjUtil {
} }
} }
/** /**
* <h2>深度克隆对象</h2> * <h2>深度克隆对象</h2>
* <p> * <p>

View File

@ -11,4 +11,10 @@ public @interface ToUeProperty {
* @return * @return
*/ */
String value() default ""; String value() default "";
/**
* 是否忽略该字段默认false
* @return
*/
boolean ignore() default false;
} }