200字范文,内容丰富有趣,生活中的好帮手!
200字范文 > 使用MyBatis select数据库查出有数据 但返回对象为null时的解决办法

使用MyBatis select数据库查出有数据 但返回对象为null时的解决办法

时间:2018-12-06 01:44:46

相关推荐

使用MyBatis select数据库查出有数据 但返回对象为null时的解决办法

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

在此测试结果如下:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。