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參數(shù):" + 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
+ "]的參數(shù)為未知的數(shù)據(jù)類型,無法進(jìn)行轉(zhuǎn)換");
}
}
} catch (Exception e) {
this.logger.error(e.getMessage(), e);
e.printStackTrace();
throw new SystemException("從ServletRequest中獲得dataentity錯(cuò)誤", e);
}
}
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。