mybatis日期缺失时分秒问题

用习惯了mybatis-plus,最近项目用mybatis时发现个坑,日期查出来为 2022-06-15 00:00:00,记下解决方案。

问题出在xml的 jdbcType上

<resultMap id="BaseResultMap" type="com.bangdao.ms.common.dal.pojo.opinion.XXXX">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="create_time" jdbcType="DATE" property="createTime"/>
        <result column="update_time" jdbcType="DATE" property="updateTime"/>
    </resultMap>
    <select id="selectById" parameterType="long" resultMap="BaseResultMap">
        select *
        from xxxx
        where id = #{id}
    </select>

只要将DATE类型改成TIMESTAMP,如下

<resultMap id="BaseResultMap" type="com.bangdao.ms.common.dal.pojo.opinion.XXXX">
        <id column="id" jdbcType="BIGINT" property="id"/>
        <result column="create_time" jdbcType="TIMESTAMP" property="createTime"/>
        <result column="update_time" jdbcType="TIMESTAMP" property="updateTime"/>
    </resultMap>
    <select id="selectById" parameterType="long" resultMap="BaseResultMap">
        select *
        from xxxx
        where id = #{id}
    </select>