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);
        }
  • 相关阅读:
    C#实现汉字转换为拼音缩写的代码
    C# 使用xsd文件验证XML 格式是否正确
    C#用天气预报的WebServices
    c# socket通信较完善方案
    C#操作MySQL数据库-----HelloWorld
    c# 自己制作一个简单的项目倒计时器
    C# 制作外挂常用的API
    C#中如何计算时间差?
    C# 图片保存到数据库和从数据库读取图片并显示
    c#加密 可逆与不可逆MD5 加密
  • 原文地址:https://www.cnblogs.com/756623607-zhang/p/10420697.html
Copyright © 2011-2022 走看看