Java中类型转换

//转换成Integer类型
public static Integer TryParseToInteger(Object obj, String name) throws ApiSrvException {
Integer result = null;
if (obj != null&&!obj.equals("")) {
try {
result = Integer.valueOf(obj.toString());
}catch (Exception ex){
throw new ApiSrvException(name + "类型转换失败", ExCode.MSG_RESOLVE_ERR, new IllegalArgumentException());
}
}
return result;
}

//转换成BigDecimal类型
public static BigDecimal TryParseToBigDecimal(Object obj, String name) throws ApiSrvException {
BigDecimal result = null;
if (obj != null&&!obj.equals("")) {
try {
result = new BigDecimal(obj.toString());
} catch (Exception ex){
throw new ApiSrvException(name + "类型转换失败", ExCode.MSG_RESOLVE_ERR, new IllegalArgumentException());
}
}
posted @ 2019-03-20 17:03  小芝麻开花  阅读(207)  评论(0编辑  收藏  举报