1.BigDecimal 获取Map中计数的工具方法
package com.mytest.utils;
import java.math.BigDecimal;
import java.util.Map;
public class BigDecimalUtils {
public static BigDecimal getBigDecimal(Map<String,Object> map,Object key){
if(map!=null){
Object answer = map.get(key);
if(answer!=null){
if(answer instanceof Number){
return new BigDecimal(answer.toString());
}
if(answer instanceof String){
return new BigDecimal((String) answer);
}
}
return new BigDecimal("0.00");
}
return null;
}
}
2.获取Map中参数,及转换map
package com.mytest.utils;
import java.util.Map;
public class MapUtils {
public static String getString(Map map,Object key){
if(map!=null){
Object answer = map.get(key);
if (answer!=null){
return answer.toString();
}
}
return null;
}
public static Map getMap(Map map,Object key){
if(map!=null){
Object answer = map.get(key);
if(answer!=null && answer instanceof Map){
return (Map) answer;
}
}
return null;
}
public static Object getObject(Map map, Object key){
if(map!=null){
return map.get(key);
}
return null;
}
}
3.推荐下hutool工具包,很实用,国内开发者
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.1.0</version>
</dependency>