public void convertMapToDataEntity(Map map) throws SystemException {
Field[] fields = super.getClass().getDeclaredFields();
String strValue = null;
Field currField = null;
String currFieldName = null;
String currFieldTypeName = null;
String methodName = null;
Method currMethod = null;
try {
for (int i = 0; i < fields.length; ++i) {
currField = fields[i];
currFieldName = currField.getName();
if (!(map.containsKey(currFieldName.toLowerCase())))
continue;
strValue = (String) map.get(currFieldName.toLowerCase());
this.logger.debug("map参数:" + currFieldName + " = " + strValue);
if ((strValue == null) || (strValue.equals("")))
continue;
currFieldTypeName = currField.getType().getName();
methodName = "set"
+ currFieldName.substring(0, 1).toUpperCase()
+ currFieldName.substring(1);
if (currFieldTypeName.equals(Double.TYPE.getName())) {
currMethod = super.getClass().getMethod(methodName,
new Class[] { Double.TYPE });
currMethod.invoke(this, new Object[] { new Double(
DataFormat.parseNumber(strValue.trim())) });
} else if (currFieldTypeName.equals(Long.TYPE.getName())) {
currMethod = super.getClass().getMethod(methodName,
new Class[] { Long.TYPE });
currMethod.invoke(this,
new Object[] { new Long(strValue.trim()) });
} else if (currFieldTypeName.equals(Timestamp.class.getName())) {
currMethod = super.getClass().getMethod(methodName,
new Class[] { Timestamp.class });
currMethod.invoke(this, new Object[] { DataFormat
.getDateTime(strValue.trim()) });
} else if (currFieldTypeName.equals(Date.class.getName())) {
currMethod = super.getClass().getMethod(methodName,
new Class[] { Date.class });
currMethod.invoke(this, new Object[] { DataFormat
.parseDate(strValue.trim()) });
} else if (currFieldTypeName.equals(String.class.getName())) {
currMethod = super.getClass().getMethod(methodName,
new Class[] { String.class });
currMethod.invoke(this, new Object[] { strValue.trim() });
} else {
this.logger.error("方法[" + methodName
+ "]的参数为未知的数据类型,无法进行转换");
}
}
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
e.printStackTrace();
throw new SystemException("从ServletRequest中获得dataentity错误", e);
}
}
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。