本文主要是介绍mybatis查询数据赋值到model里面为空,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
因为数据多所以在查询中使用分页,但是发现直接执行sql语句是可以获取到数据,而list里面却是空的
<select id="list" resultType="DaliyDO">select a1.* from (selectid ,rownumfrom dual <where><if test="id != null and id != ''"> and id = #{id} </if></where><choose><otherwise>order by id desc</otherwise></choose>) a1<if test="offset != null and limit != null">where rownum between #{offset} and #{offset}+#{limit}</if></select>
原因是 resultType属性与model不对应。
我们使用分页会在查询值加入一个rownum的值,这个值在我们建立model的时候是没有的,所以只要在model里面加上rownum这个属性就可以。
当然你也可以使用别的分页方法
这篇关于mybatis查询数据赋值到model里面为空的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!