将一个对象的所有字段名称和值放到map
假设
value为对象 ,类为entityClass
private Class entityClass;
Map<String, String> entityColumnMap = new HashMap<String, String>();PropertyDescriptor[] propDescs = PropertyUtils.getPropertyDescriptors(entityClass);for (PropertyDescriptor propDesc : propDescs) {String propertyName = propDesc.getName();if("class".equals(propertyName)) {continue;}String propertyValue = "";try {Object propertyValueObject = PropertyUtils.getProperty(value, propertyName);if(propertyValueObject!=null) {propertyValue = "" + propertyValueObject;} else {propertyValue = null;}} catch (IllegalAccessException e) {e.printStackTrace();} catch (InvocationTargetException e) {e.printStackTrace();} catch (NoSuchMethodException e) {e.printStackTrace();}System.out.println(propertyName + " -> " + propertyValue);entityColumnMap.put(propertyName, propertyValue); }