UAT问题清单-222条问题修改,上报库-一般导出开发。
This commit is contained in:
+48
@@ -0,0 +1,48 @@
|
||||
package com.jero.common.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* 实体工具类
|
||||
*/
|
||||
public class BeanUtils {
|
||||
/**
|
||||
* 实体对象转Map
|
||||
* @param entity
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> Map<String, Object> entityToMap(T entity) {
|
||||
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
|
||||
List<Field> fieldList = new ArrayList<>();
|
||||
|
||||
Class<?> clazz = entity.getClass();
|
||||
Field[] fields = clazz.getDeclaredFields();
|
||||
fieldList.addAll(Arrays.asList(fields));
|
||||
|
||||
Field[] superFields = clazz.getSuperclass().getDeclaredFields();
|
||||
fieldList.addAll(Arrays.asList(superFields));
|
||||
|
||||
for (Field field : fieldList) {
|
||||
|
||||
field.setAccessible(true);
|
||||
|
||||
try {
|
||||
|
||||
map.put(field.getName(), field.get(entity));
|
||||
|
||||
} catch (IllegalAccessException e) {
|
||||
|
||||
e.printStackTrace();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return map;
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user