zoukankan      html  css  js  c++  java
  • 表结构中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);
        }
  • 相关阅读:
    级联操作
    深入解析http协议
    http状态码
    数据库在一对一、一对多、多对多怎么设计表关系
    [转载]C#深拷贝的方法
    TraceSource记录程序日志
    .NET 垃圾回收与内存泄漏
    DevExpress GridControl使用方法总结
    DevExpress使用技巧总结
    Oracle 错误代码小结
  • 原文地址:https://www.cnblogs.com/756623607-zhang/p/10420697.html
Copyright © 2011-2022 走看看