zoukankan      html  css  js  c++  java
  • FieldGroup绑定的日期类型存储格式的问题

    问题

      日期存储的时候,当前数据库中存储格式为 "2017-9-5 0:00:00",
      而我实现了以后,看到数据库的存储格式为 "Mon Sep 04 00:00:00 CST 2017"

      原因找了很久,是在为FieldGroup 添加PropertysetItem 时的问题

    比较

    //第一种存储方式的实现为:
    PropertysetItem item = new PropertysetItem();
    item.addItemProperty("{code_act_Date1}",new ObjectProperty(""));
    FieldGroup fieldGroup = new FieldGroup(item);
    
    //第二种存储方式的实现为:
    PropertysetItem item = new PropertysetItem();
    item.addItemProperty("{code_act_Date1}",new DateField());
    FieldGroup fieldGroup = new FieldGroup(item);

      这两种实现,在下面的代码中会走不同的判断,因为他们的Type不一样,而这个Type不能直接set,只能根据上面的那种方法添加。

    if (propertysetItem.getItemProperty(key).getType() == Date.class) {
        Date date = new Date((String) mapValues.get(key));
        propertysetItem.getItemProperty(key).setValue(date);
    } else {
        propertysetItem.getItemProperty(key).setValue(mapValues.get(key));
    }

       奇葩就奇葩在,直接把日期类型存储为字符串类型,居然也没问题,可以正好的转换成"yyyy-MM-dd HH:mm:ss"格式。

      而且事实证明,所有情况下都没有走过getType() == Date.class这个判断。我就觉得奇怪嘛,没用到日期格式化,直接把String转换成Date类型居然不报错,原来是从来没走过这个方法。 

    比较两种类型保存在FieldGroup中的区别

    new DateField()

    new ObjectProperty("")

  • 相关阅读:
    QQ下面功能移动效果
    网页中选择功能
    自定义listview
    android的内存优化分析【转,超级推荐】
    animation的xml定义中的android:interpolator属性(转)
    HOME键与Notification配合使用的bug重现【原创】
    (转载)Android下Affinities和Task(开发者指南)
    职场加薪步步高升的五大法则(转)
    强引用,软引用和弱引用。
    更改字体的ttf。
  • 原文地址:https://www.cnblogs.com/acm-bingzi/p/cubaFieldGroupDate.html
Copyright © 2011-2022 走看看