1. 程式人生 > >MySQL中Date和DateTime欄位與mybatis的對應關係

MySQL中Date和DateTime欄位與mybatis的對應關係

MySQL中Date和DateTime欄位與mybatis的對應關係

在MySQL欄位中有Date和DateTime型別,但是java中沒有DateTime型別。
解決辦法:
(1)在mybatis插入資料時只要將實體的屬性設定成Timestamp就會對應mysql的DateTime型別,
(2)將實體的屬性設定成Date會對應mysql的Date型別。
<result column="maketime" property="maketime" jdbcType="TIMESTAMP" /> <result column="activetime" property="activetime" jdbcType="DATE" />


使用過程中注意設定

<if test="maketime != null" >
        #{maketime,jdbcType=TIMESTAMP},
</if>
 <if test="activetime != null" >
        #{activetime,jdbcType=DATE},
 </if>