/** * @param src * @param dest * @param filedMapping the diffrent fieldName mapping,key is src filename and value is dest filedname */ public <S, T> void copyProperties(S src, T dest, Map<String, String> filedMapping) { BeanUtils.copyProperties(src, dest); Class sClass = src.getClass(); Class tClass = dest.getClass(); Set<Map.Entry<String, String>> mappingSet = filedMapping.entrySet(); for (Map.Entry<String, String> en : mappingSet) { String srcFiledName = en.getKey(); String destFiledName = en.getValue(); try { Field srcFiled = sClass.getDeclaredField(srcFiledName); Field destFiled = tClass.getDeclaredField(destFiledName); srcFiled.setAccessible(true); destFiled.setAccessible(true); Object value = srcFiled.get(src); destFiled.set(dest, value); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (NoSuchFieldException e) { // igonre the not found field error } } }