package com.ruoyi.utils.tools; import java.lang.reflect.Field; import java.util.*; /** * @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; } /** * 求Map中最小 Value 对应的Key值 * * @param map * @return */ public static String getKeyByMinValue(Map map) { if (map == null) return null; List> list = new ArrayList(map.entrySet()); Collections.sort(list, (o1, o2) -> (o1.getValue().intValue() - o2.getValue().intValue())); String min = list.get(0).getKey(); // String max = list.get(list.size() - 1).getKey(); return min; } }