class="java" name="code"> public String DifferentOfTwoVO(String empName,GbsExtendedVO oldVO,GbsExtendedVO newVO){ String str=empName; String nullStr= empName; if(oldVO==null){ str=str+"添加数据:"; nullStr=nullStr+"添加数据:"; try { Class clazz = newVO.getClass(); Field[] fields = newVO.getClass().getDeclaredFields(); int i=1; for (Field field : fields) { if("serialVersionUID".equals(field.getName())|| "creator".equals(field.getName())|| "creatorName".equals(field.getName())|| "createTime".equals(field.getName())){ continue; } PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz); Method getMethod = pd.getReadMethod(); Object o2 = getMethod.invoke(newVO); if(o2 == null){ continue; }else{ if(i!=1){ str+=";"; } str+=i+";字段名称"+field.getName()+"的新值:"+o2; i++; } } } catch (Exception e) { e.printStackTrace(); } }else{ str=str+"修改数据:"; nullStr=nullStr+"修改数据:"; try { Class clazz = newVO.getClass(); Field[] fields = newVO.getClass().getDeclaredFields(); int i=1; for (Field field : fields) { if("serialVersionUID".equals(field.getName())|| "creator".equals(field.getName())|| "creatorName".equals(field.getName())|| "createTime".equals(field.getName())){ continue; } PropertyDescriptor pd = new PropertyDescriptor(field.getName(), clazz); Method getMethod = pd.getReadMethod(); Object o1 = getMethod.invoke(oldVO); Object o2 = getMethod.invoke(newVO); if(o1==null && o2 == null){ continue; }else if (o1!=null && o2 != null){ if (!o1.toString().equals(o2.toString())) { if(i!=1){ str+=";"; } str+=i+";字段名称"+field.getName()+",旧值:"+o1+",新值:"+o2; i++; } }else if(o1==null && o2 != null){ if(i!=1){ str+=";"; } str+=i+";字段名称"+field.getName()+",旧值:空"+",新值:"+o2; i++; }else if(o1!=null && o2 == null){ if(i!=1){ str+=";"; } str+=i+";字段名称"+field.getName()+",旧值:"+o1+",新值:空"; i++; } } } catch (Exception e) { e.printStackTrace(); } } if(nullStr.equals(str)){ return null; } return str; }