提交 | 用户 | age
|
736fa6
|
1 |
package com.hx.util; |
G |
2 |
|
0241af
|
3 |
import java.math.BigDecimal; |
736fa6
|
4 |
import java.util.Map; |
G |
5 |
|
|
6 |
/** |
|
7 |
* map工具类 |
|
8 |
* |
|
9 |
* @author cmg |
|
10 |
* @date 2023-03-16 |
|
11 |
*/ |
|
12 |
public class MapUtil { |
|
13 |
|
|
14 |
/** |
|
15 |
* 从map中获取 |
|
16 |
* @param map |
|
17 |
* @param key |
|
18 |
* @return |
|
19 |
*/ |
|
20 |
public static String getString(Map<String, Object> map, String key) |
|
21 |
{ |
|
22 |
if(map == null || StringUtils.isEmpty(key)) |
|
23 |
{ |
|
24 |
return null; |
|
25 |
} |
|
26 |
|
|
27 |
return null == map.get(key) ? null : map.get(key).toString(); |
|
28 |
} |
|
29 |
|
|
30 |
/** |
|
31 |
* 从map中获取整数,如果没有,则返回-1 |
|
32 |
* @param map |
|
33 |
* @param key |
|
34 |
* @return |
|
35 |
*/ |
|
36 |
public static int getInt(Map<String, Object> map, String key) |
|
37 |
{ |
|
38 |
if(map == null || StringUtils.isEmpty(key)) |
|
39 |
{ |
|
40 |
return -1; |
|
41 |
} |
|
42 |
|
|
43 |
return null == map.get(key) ? -1 : Integer.parseInt(map.get(key).toString()); |
|
44 |
} |
0df24c
|
45 |
|
G |
46 |
/** |
|
47 |
* 从map中获取整数,如果没有,则返回0 |
|
48 |
* @param map |
|
49 |
* @param key |
|
50 |
* @return |
|
51 |
*/ |
|
52 |
public static int getIntZero(Map<String, Object> map, String key) |
|
53 |
{ |
|
54 |
if(map == null || StringUtils.isEmpty(key)) |
|
55 |
{ |
|
56 |
return 0; |
|
57 |
} |
|
58 |
|
|
59 |
return null == map.get(key) ? 0 : Integer.parseInt(map.get(key).toString()); |
|
60 |
} |
0241af
|
61 |
|
F |
62 |
/** |
|
63 |
* 从map中获取数字类型对象 |
|
64 |
* @param map |
|
65 |
* @param key |
|
66 |
* @return |
|
67 |
*/ |
|
68 |
public static BigDecimal getBigDecimal(Map<String, Object> map, String key) |
|
69 |
{ |
|
70 |
if(map == null || StringUtils.isEmpty(key)) |
|
71 |
{ |
|
72 |
return BigDecimal.ZERO; |
|
73 |
} |
|
74 |
|
|
75 |
return null == map.get(key) ? BigDecimal.ZERO : new BigDecimal(map.get(key).toString()); |
|
76 |
} |
aa1d39
|
77 |
|
G |
78 |
/** |
|
79 |
* 获取浮点数,默认返回0 |
|
80 |
* @param map |
|
81 |
* @param key |
|
82 |
* @return |
|
83 |
*/ |
|
84 |
public static Double getDoubleZero(Map<String, Object> map, String key) |
|
85 |
{ |
|
86 |
if(map == null || StringUtils.isEmpty(key)) |
|
87 |
{ |
|
88 |
return 0D; |
|
89 |
} |
|
90 |
|
|
91 |
return null == map.get(key) ? 0D : Double.parseDouble(map.get(key).toString()); |
|
92 |
} |
736fa6
|
93 |
} |