Same comparison return true
import java.beans.Introspector; import java.beans.PropertyDescriptor; import
java.lang.reflect.Method; import java.sql.Timestamp; import java.util.ArrayList;
import java.util.Arrays; import java.util.Date; import java.util.HashMap; import
java.util.List; import java.util.Map; /** * <p> * Compare values between two objects * </p> * * @author
chen * @date 2021 */ public class CompareUtil { /** *
Compare two entity attribute values , Return a boolean,true There is no difference in attribute values between the two objects when the table * @param oldObject Object for attribute comparison 1 *
@param newObject Object for attribute comparison 2 * @return Attribute difference comparison results boolean */ public static boolean
compareObject(Object oldObject, Object newObject) { Map<String, List<Object>>
resultMap=compareFields(oldObject,newObject,null);
//System.out.println("resultMap------------"+resultMap); if(resultMap.size()>0)
{ return false; }else { return true; } } /** *
Compare two entity attribute values , Return a map Named with different attribute names key,value For one Map Separate storage oldObject,newObject The value of this property name * @param
obj1 Object for attribute comparison 1 * @param obj2 Object for attribute comparison 2 * @param ignoreArr Ignore fields for comparison * @return
Attribute difference comparison results map */ @SuppressWarnings("rawtypes") public static Map<String, List<
Object>> compareFields(Object obj1, Object obj2, String[] ignoreArr) { try{ Map<
String, List<Object>> map = new HashMap<String, List<Object>>(); List<String>
ignoreList= null; if(ignoreArr != null && ignoreArr.length > 0){ // array Convert to list
ignoreList= Arrays.asList(ignoreArr); } if (obj1.getClass() == obj2.getClass())
{// Only two objects of the same type are comparable Class clazz = obj1.getClass(); // obtain object Attribute description for
PropertyDescriptor[] pds = Introspector.getBeanInfo(clazz, Object.class).
getPropertyDescriptors(); for (PropertyDescriptor pd : pds) {// Here are all the attributes
String name = pd.getName();// Attribute name if(ignoreList != null && ignoreList.contains(
name)){// If the current attribute is selected, ignore the comparison , Skip to next cycle continue; } Method readMethod = pd.getReadMethod(
);// get method // stay obj1 Call on get Method is equivalent to obtaining obj1 Attribute value for Object o1 = readMethod.invoke(obj1);
// stay obj2 Call on get Method is equivalent to obtaining obj2 Attribute value for Object o2 = readMethod.invoke(obj2); if(o1
instanceof Timestamp){ o1 = new Date(((Timestamp) o1).getTime()); } if(o2
instanceof Timestamp){ o2 = new Date(((Timestamp) o2).getTime()); } if(o1 ==
null && o2 == null){ continue; }else if(o1 == null && o2 != null){ List<Object>
list= new ArrayList<Object>(); list.add(o1); list.add(o2); map.put(name, list);
continue; } if (!o1.equals(o2)) {// Compare whether the two values are equal , You can put it in without waiting map Yes List<Object> list =
new ArrayList<Object>(); list.add(o1); list.add(o2); map.put(name, list); } } }
return map; }catch(Exception e){ e.printStackTrace(); return null; } } }

Technology
©2019-2020 Toolsou All rights reserved,
Android Using wechat in H5 Payment result refresh during payment shock !!C++ Can make a sound ! Basic operation of single linked list C Language explanation Java Implement an epidemic number management system 2021 year 11 World programming language ranking linux upper mysql Invalid command _linux lower mysql The command is useless Java project : Campus dormitory management system (java+jsp+javaweb+mysql+ajax) Wechat applet development project directory linux ubuntu Which version ,Ubuntu Which version is the best ?python Code painting cherry blossoms - How to use Python Draw a beautiful cherry blossom