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

因为数据多所以在查询中使用分页,但是发现直接执行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>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

原因是 resultType属性与model不对应。 我们使用分页会在查询值加入一个rownum的值,这个值在我们建立model的时候是没有的,所以只要在model里面加上rownum这个属性就可以。 当然你也可以使用别的分页方法

上次更新: 2024-01-03, 13:22:13
最近更新
01
2023年度总结
01-03
02
MongoDB的简单的常用语法
12-11
03
cetnos7通过nfs共享磁盘文件
11-24
更多文章>