1. 时间出现yyyy-MM-dd HH:mm:ss.0 的情况:
今天有个同事和我反馈是数据库中时间没有后面的.0 ,通过mybatis 查询出来的数据出现了, 是因为映射类型不一致导致的。
案例:在实体中使用的是String, 在配置文件中使用的是VARCHAR, 查询出来开的就会映射成为yyyy-MM-dd HH:mm:ss.0 格式
- <result column="created_time" jdbcType="VARCHAR" property="createTime" />
- <result column="pay_time" jdbcType="VARCHAR" property="payTime" />
问题解决:
<!-- 在实体中, 修改类型和数据库的对应, 数据库字段:timestamp; 实体用Date, 两个类型对应后, 就不会出现.0 -->
- <result column="created_time" jdbcType="TIMESTAMP" property="createTime" />
- <result column="pay_time" jdbcType="TIMESTAMP" property="payTime" />
2. Mybatis 找不到数据库驱动Driver:
MyBatis异常 Error setting driver on UnpooledDataSource. Cause: java.lang.ClassNotFoundException:
原因是因为: 没有引入配置文件。
<!-- 引入properties 文件 -->
<properties resource="jdbc.properties"></properties>
3. 由于做更新操作, 但是使用了select 标签导致的:
attempted to return null from a method with a primitive return type (int).
- <select id="updateOffLineRepositoryShelf" parameterType="java.util.Map" >
- update repository_shelf set issuance = #{issuance} where spu_id in
- <foreach item="item" index="index" collection="spuIds" open="(" separator="," close=")"> #{item}</foreach>
- </select>