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 * @创建人 刘苏义 * @创建时间 2023/6/2 14:35 * @修改人和其它信息 */ public static Map convertEntityToMap(Object entity) { Map 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; } }