/**
* 不同实体类,相同的属性赋值
*
* @param sourceData
* @param toData
* @param <T>
*/
public static <T> void copyFields(T sourceData, T toData) {
if (sourceData == null || toData == null)
return;
Field[] fields = sourceData.getClass().getDeclaredFields();
try {
for (Field field : fields) {
field.setAccessible(true);
Object value = field.get(sourceData);
if (null != value && !"".equals(value)) {
Field toField = toData.getClass().getDeclaredField(field.getName());
if (toField != null) {
toField.setAccessible(true);
toField.set(toData, value);
}
}
}
} catch (Exception ignored) {
}
}