‘liusuyi’
2023-06-02 3cadca8ab0c0db03f072c5eb55c5703cd6965d9d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package com.ruoyi.common.utils.tools;
 
import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.Map;
 
/**
 * @Description: 工具方法
 * @ClassName: ArdTool
 * @Author: 刘苏义
 * @Date: 2023年06月02日14:37
 * @Version: 1.0
 **/
public class ArdTool {
 
    /**
     * @描述 实体对象转Map
     * @参数 [entity]
     * @返回值 java.util.Map<java.lang.String,java.lang.Object>
     * @创建人 刘苏义
     * @创建时间 2023/6/2 14:35
     * @修改人和其它信息
     */
    public static Map<String, Object> convertEntityToMap(Object entity) {
        Map<String, Object> map = new HashMap<>();
        Field[] fields = entity.getClass().getDeclaredFields();
        for (Field field : fields) {
            field.setAccessible(true);
            try {
                Object value = field.get(entity);
                map.put(field.getName(), value);
            } catch (IllegalAccessException e) {
                e.printStackTrace();
            }
        }
        return map;
    }
}