mybatis查询数据赋值到model里面为空

版权声明:本文为博主原创文章,未经博主允许不得转载。转载请注明出处 https://blog.csdn.net/tutian2000/article/details/80194783

因为数据多所以在查询中使用分页,但是发现直接执行sql语句是可以获取到数据,而list里面却是空的

<select id="list" resultType="DaliyDO">
        select a1.* from (
            select
                id ,rownum
            from 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这个属性就可以。
当然你也可以使用别的分页方法

猜你喜欢

转载自blog.csdn.net/tutian2000/article/details/80194783