成都创新互联网站制作重庆分公司

将集合转换为实体数据-创新互联

public void convertMapToDataEntity(Map map) throws SystemException {
  Field[] fields = super.getClass().getDeclaredFields();
  String strValue = null;

成都创新互联公司是专业的沛县网站建设公司,沛县接单;提供网站设计、成都网站设计,网页设计,网站设计,建网站,PHP网站建设等专业做网站服务;采用PHP框架,可快速的进行沛县网站开发网页制作和功能扩展;专业做搜索引擎喜爱的网站,专业的做网站团队,希望更多企业前来合作!

  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);
  }
 }

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网页标题:将集合转换为实体数据-创新互联
文章路径:http://cxhlcq.com/article/hhpos.html

其他资讯

在线咨询

微信咨询

电话咨询

028-86922220(工作日)

18980820575(7×24)

提交需求

返回顶部