这篇文章主要介绍了MySQL MyBatis 默认插入当前时间方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
MySQL MyBatis 默认插入当前时间
<!--单表动态更新语句 -->
<update id="update" parameterType="com.zzg.entity.ColumnValidate">
update ucas_bus_column_validate
<set>
<if test="updateBy != null and updateBy != ''">
update_by = #{updateBy,jdbcType=VARCHAR},
</if>
<if test="state != null and state != ''">
`state` = #{state,jdbcType=VARCHAR},
</if>
<if test="deleteFlag != null and deleteFlag != ''">
delete_flag = #{deleteFlag,jdbcType=VARCHAR},
</if>
<if test="validateName != null and validateName != ''">
validate_name = #{validateName,jdbcType=VARCHAR},
</if>
<if test="validateContent != null and validateContent != ''">
validate_content = #{validateContent,jdbcType=VARCHAR},
</if>
version = version + 1,
update_dt = now()
</set>
where sid = #{sid,jdbcType=VARCHAR} and version = #{version, jdbcType=INTEGER}
</update>
重点代码:update_dt = now()
MyBatis 插入时间类型的数据
数据库indbTime字段类型:date
实体中类型是:Date
mybatis的插入类型应该设置成:#{indbTime,jdbcType=TIMESTAMP}
mybatis的插入类型应该设置成: #{indbTime,jdbcType=DATE}
insert into CDS_DATA_PLAT_TRANS_INFO
<trim prefix="(" suffix=")" suffixOverrides=",">
<if test="indbTime != null">
INDB_TIME,
</if>
</trim>
<trim prefix="values (" suffix=")" suffixOverrides=",">
<if test="indbTime != null">
#{indbTime,jdbcType=TIMESTAMP},
</if>
</trim>
</insert>
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程学习网。
织梦狗教程
本文标题为:MySQL MyBatis 默认插入当前时间方式


基础教程推荐
猜你喜欢
- 工厂方法在Spring框架中的运用 2023-06-23
- 一文了解Java 线程池的正确使用姿势 2023-06-17
- Java File类的概述及常用方法使用详解 2023-05-18
- 全局记录Feign的请求和响应日志方式 2023-01-09
- JVM分析之类加载机制详解 2023-04-06
- SpringBoot配置文件中密码属性加密的实现 2023-03-11
- Java去掉小数点后面无效0的方案与建议 2023-02-18
- 用java实现扫雷游戏 2022-12-06
- Project Reactor源码解析publishOn使用示例 2023-04-12
- Java使用EasyExcel进行单元格合并的问题详解 2023-01-18