• 表结构中updated_time设计为ON UPDATE CURRENT_TIMESTAMP时,使用过程的一个坑


    一、mysql表结构中存在如下设计时

    表结构中updated_time设计为ON UPDATE CURRENT_TIMESTAMP时,如下

    `updated_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间';

    二、使用过程的一个坑即存在的问题:

    当update整个dao实体对象时,又没有将该对象中的updateTime字段设置为null或new date();

      update time不会更新为最新时间

    三、解决方式
    1.调用xxxDAO的update方法时,update的对象中存在update time(更新时间)时,请手动set一个 new Date() 或 null;

    2.  BeanUtils.copyProperties(form, tConsultant,"updateTime"); copy的复制可以指定要忽略的updateTime字段

    spring中该方法的源码如下:

    /**
         * Copy the property values of the given source bean into the given target bean,
         * ignoring the given "ignoreProperties".
         * <p>Note: The source and target classes do not have to match or even be derived
         * from each other, as long as the properties match. Any bean properties that the
         * source bean exposes but the target bean does not will silently be ignored.
         * <p>This is just a convenience method. For more complex transfer needs,
         * consider using a full BeanWrapper.
         * @param source the source bean
         * @param target the target bean
         * @param ignoreProperties array of property names to ignore
         * @throws BeansException if the copying failed
         * @see BeanWrapper
         */
        public static void copyProperties(Object source, Object target, String... ignoreProperties) throws BeansException {
            copyProperties(source, target, null, ignoreProperties);
        }
  • 相关阅读:
    从淘宝数据结构来看电子商务中商品属性设计
    YY淘宝商品数据库设计
    ElasticSearch-聚合bucket学习
    ElasticSearch-聚合bucket
    Elasticsearch(9) --- 聚合查询(Bucket聚合)
    Elasticsearch-多字段搜索(Multifield Search)和提高精确度
    五、设备管理与文件系统
    六、YUM仓库
    四、查找命令
    二、用户权限
  • 原文地址:https://www.cnblogs.com/756623607-zhang/p/10420697.html
Copyright © 2020-2023  润新知