时间:2022-10-08 12:55:11 | 栏目:JAVA代码 | 点击:次
因为数据多所以在查询中使用分页,但是发现直接执行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这个属性就可以。
当然你也可以使用别的分页方法
1.如果返回值是List、Map这种集合类,会先执行new语句,再赋值。所以判断是否有数据时,只能用size==0来判断。
2.如果是普通的对象,不会new,所以可以使用是否为null来判断是否有数据。