MySQL MyBatis 默认插入当前时间方式

2022-11-13 18:11:10 默认 方式 插入

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>

以上为个人经验,希望能给大家一个参考,也希望大家多多支持。

相关文章