以下代码可以在有“代码混淆器,混淆后正常工作”,希望分享给有可以使用到的人,(*^__^*) 嘻嘻
/*
* HashMapToPo 转换为集合对象
*/
public static
final ArrayList
final Class
throws ForerDealArgumentException {
if (hmList == null || clazz == null) {
String msg = className
+ ".HashMapToPoList(final ArrayList
logger.error(msg);
throw new ForerDealArgumentException(msg);
}
final HashMap
final HashMap
final ArrayList
for (HashMap
T o = null;
try {
o = clazz.newInstance();
} catch (final Exception e) {
e.printStackTrace();
}
for (Map.Entry
String key = entry.getKey().toUpperCase().replace("_", "");
Object value = entry.getValue();
if (dic.containsKey(key) && value != null) {
try {
String str = dic.get(key);
String temp = str.substring(0, 1);
str = str.replaceFirst(temp, temp.toUpperCase());
str = "set" + str;
Class< > paraType = dic2.get(str).getParameterTypes()[0];
if (paraType != value.getClass())// 类型一致
value = StringToObject(paraType, value.toString());
if (isEncode) {
if (encode) {// iso8859-1 编码
if (paraType == String.class) {
value = CharsetConvert.charsetConvert(value
.toString());
}
} else {// GBK
if (paraType == String.class) {
value = CharsetConvert
.ISO_8859_1ToGBK(value.toString());
}
}
}
try {
dic2.get(str).invoke(o, value);
} catch (Exception e) {
logger.error("paraType:" + paraType + ";valueType:"
+ value.getClass() + "[" + str + ":"
+ value + "]");
}
} catch (Exception e) {
e.printStackTrace();
}
} else if (!dic.containsKey(key)) {
String msg = clazz.getName()
+ "Object does not contain the '" + key + "' field";
logger.debug(msg);
}
}
lt.add(o);
}
return lt;
}
* 字段类型转换
*/
private static Object StringToObject(Class< > clazz, String str) {
Object o = str;
if (clazz == Date.class && str != null && str != "") {
DateFormat dt1 = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
try {
o = dt1.parse(str);
} catch (ParseException e1) {
DateFormat dt2 = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
try {
o = dt2.parse(str);
} catch (ParseException e2) {
DateFormat dt3 = new SimpleDateFormat("yyyyMMdd HH:mm:ss");
try {
o = dt3.parse(str);
} catch (ParseException e3) {
DateFormat dt4 = new SimpleDateFormat("yyyyMMdd");
try {
o = dt4.parse(str);
} catch (ParseException e4) {
e4.printStackTrace();
}
}
}
}
} else if (clazz == BigDecimal.class) {
o = new BigDecimal(str);
} else if (clazz == Long.class) {
o = new Long(str);
} else if (clazz == Integer.class) {
o = new Integer(str);
} else if (clazz == int.class) {
o = Integer.parseInt(str);
} else if (clazz == float.class) {
o = Float.parseFloat(str);
} else if (clazz == boolean.class) {
o = Boolean.parseBoolean(str);
} else if (clazz == byte.class) {
o = Byte.parseByte(str);
}
return o;
}
/*
* HashMap转换为单一对象www.2cto.com
*/
public static
final Class
throws Exception {
if (hm == null || clazz == null) {
String msg = className
+ ".HashMapToSinglePo(final ArrayList
logger.error(msg);
}
T o = null;
ArrayList
hmList.add(hm);
ArrayList
if (lt != null && lt.size() > 0) {
o = lt.get(0);
}
return o;
}
/*
* 对象比较 ,结果HashMap
* ,不同Different,不存在Object does n