今天使用mybatis查询数据库是遇到一问题如下:
其中时间字段查询结果为null
问题原因:实体类中属性与表中字段不一致时,添加resultMap进行重新关联实体类。
解决如下:
mapper XML文件中添加如下:
<resultMap id="studentMap" type="Student">
<id column="id" property="id" jdbcType="INTEGER"/>
<result column="name" property="name" jdbcType="VARCHAR"/>
<result column="sex" property="sex" jdbcType="VARCHAR"/>
<result column="age" property="age" jdbcType="INTEGER"/>
<result column="input_time" property="inputIime" jdbcType="TIMESTAMP"/>
</resultMap>
需改查询语句为:
<select id="findAll" resultMap="studentMap">
select id,name,sex,age,input_time from t_student
</select>
在此测试结果如下: