Mapper.xml中映射sql如下,查询返回对象Production 为null。
<select id="selectOneByTime" resultType="model.Production">
select *
from CNC_Production
where dataTime < #{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 < #{date}
limit 1
</select>