Mybatis查询返回对象为null

Mapper.xml中映射sql如下,查询返回对象Production 为null。

 <select id="selectOneByTime" resultType="model.Production">
    select *
    from CNC_Production
    where dataTime &lt; #{date}
    limit 1
  </select>

Mysql中对应表明为 XXX_Production。
表名与其生成的model名不同,resultType需要完全相同才能对应。
需要在mapper.xml文件中增加resultMap的声明。

 <resultMap id="ResultMap" type="model.Production" >
    <id column="id" property="id" jdbcType="INTEGER" />
    <result column="machineID" property="machineid" jdbcType="INTEGER" />
    <result column="yield" property="yield" jdbcType="INTEGER" />
    <result column="programCode" property="programcode" jdbcType="VARCHAR" />
    <result column="StartTime" property="starttime" jdbcType="TIMESTAMP" />
    <result column="EndTime" property="endtime" jdbcType="TIMESTAMP" />
    <result column="dataTime" property="datatime" jdbcType="TIMESTAMP" />
    <result column="status" property="status" jdbcType="INTEGER" />
    <result column="UpdateTime" property="updatetime" jdbcType="TIMESTAMP" />
  </resultMap>
  <select id="selectOneByTime" resultMap="ResultMap">
    select *
    from CNC_Production
    where dataTime &lt; #{date}
    limit 1
  </select>
发布了63 篇原创文章 · 获赞 3 · 访问量 1421

猜你喜欢

转载自blog.csdn.net/weixin_41772761/article/details/103870081
今日推荐