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);
        }
  • 相关阅读:
    BZOJ 1051: [HAOI2006]受欢迎的牛
    BZOJ 3668: [Noi2014]起床困难综合症
    BZOJ 4395: [Usaco2015 dec]Switching on the Lights
    BZOJ 2763: [JLOI2011]飞行路线
    Bzoj 3196 Tyvj 1730 二逼平衡树
    BZOJ 2407: 探险/4398: 福慧双修
    BZOJ 3040: 最短路(road)
    BZOJ 2809: [Apio2012]dispatching
    BZOJ 1651: [Usaco2006 Feb]Stall Reservations 专用牛棚
    BZOJ 4590: [Shoi2015]自动刷题机
  • 原文地址:https://www.cnblogs.com/756623607-zhang/p/10420697.html
Copyright © 2011-2022 走看看