这篇文章主要介绍了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 默认插入当前时间方式
猜你喜欢
- JSP页面间传值问题实例简析 2023-08-03
- SpringBoot使用thymeleaf实现一个前端表格方法详解 2023-06-06
- Java中的日期时间处理及格式化处理 2023-04-18
- 深入了解Spring的事务传播机制 2023-06-02
- JSP 制作验证码的实例详解 2023-07-30
- ExecutorService Callable Future多线程返回结果原理解析 2023-06-01
- Springboot整合minio实现文件服务的教程详解 2022-12-03
- 基于Java Agent的premain方式实现方法耗时监控问题 2023-06-17
- Spring Security权限想要细化到按钮实现示例 2023-03-07
- Java实现顺序表的操作详解 2023-05-19