今天使用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>