小工具开发进度
bing的自我修养
小工具开发进度
1、判断两个实体中中是否相等 的工具类
public class CheckEntity2Equal {
private static final String jumpFields = "creatorid,createtime,updaterid,updatetime,isdelete";
public static <T> Boolean checkEqual(Object targetObj, Object sourceObj) {
Boolean retFlag = true;
if (ObjectUtil.isEmpty(targetObj) || ObjectUtil.isEmpty(sourceObj)){
return false;
}
try {
Class targetClazz = Class.forName(targetObj.getClass().getName());
Field[] targetFields = targetClazz.getDeclaredFields();
Field.setAccessible(targetFields, true);
for (Field targetField : targetFields) {
if (jumpFields.contains(targetField.getName().toLowerCase(Locale.ROOT))) {
continue;
}
if (!checkBasicType(targetField)){
if (!checkEqual(targetField.getDeclaringClass(),sourceObj)){
retFlag = false;
break;
}
continue;
}else {
Class sourceClazz = Class.forName(sourceObj.getClass().getName());
Field sourceField = sourceClazz.getDeclaredField(targetField.getName());
sourceField.setAccessible(true);
Object targeto = targetField.get(targetObj);
Object sourceo = sourceField.get(sourceObj);
if (ObjectUtil.notEqual(targeto, sourceo)) {
retFlag = false;
break;
}
}
}
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (NoSuchFieldException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return retFlag;
}
private static final String type = "java.lang.string,java.lang.integer,java.lang.short,java.lang.long,java.lang.byte,java.lang.character,java.lang.boolean,java.lang.float,java.lang.double,map,java.util.date,java.math.bigdecimal";
private static Boolean checkBasicType(Field targetField){
Type genericType = targetField.getGenericType();
String typeName = genericType.getTypeName();
if (CheckEntity2Equal.type.contains(typeName.toLowerCase(Locale.ROOT))){
return true;
}
return false;
}
}