ANDRU-PC\Andru
2023-09-18 691dee7a71996cd99fdfe30bd61b2da95cc88ecd
提交 | 用户 | age
736fa6 1 package com.hx.util;
G 2
3 import java.util.Map;
4
5 /**
6  * map工具类
7  *
8  * @author cmg
9  * @date 2023-03-16
10  */
11 public class MapUtil {
12
13     /**
14      * 从map中获取
15      * @param map
16      * @param key
17      * @return
18      */
19     public static String getString(Map<String, Object> map, String key)
20     {
21         if(map == null || StringUtils.isEmpty(key))
22         {
23             return null;
24         }
25
26         return null == map.get(key) ? null : map.get(key).toString();
27     }
28
29     /**
30      * 从map中获取整数,如果没有,则返回-1
31      * @param map
32      * @param key
33      * @return
34      */
35     public static int getInt(Map<String, Object> map, String key)
36     {
37         if(map == null || StringUtils.isEmpty(key))
38         {
39             return -1;
40         }
41
42         return null == map.get(key) ? -1 : Integer.parseInt(map.get(key).toString());
43     }
0df24c 44
G 45     /**
46      * 从map中获取整数,如果没有,则返回0
47      * @param map
48      * @param key
49      * @return
50      */
51     public static int getIntZero(Map<String, Object> map, String key)
52     {
53         if(map == null || StringUtils.isEmpty(key))
54         {
55             return 0;
56         }
57
58         return null == map.get(key) ? 0 : Integer.parseInt(map.get(key).toString());
59     }
736fa6 60 }