service的page方法的sql实现,仅仅使用了limit
int pageNo = 5, pageSize = 2;
Page<User> page = Page.of(pageNo, pageSize);
page.addOrder(new OrderItem("balance", true));
page.addOrder(new OrderItem("id", true));
userService.page(page);
page方法:查询第5页,每页有2条数据
SELECT id, username, password, phone, info, status, balance, create_time, update_time FROM user ORDER BY balance ASC, id ASC LIMIT 8,2
等同于sql,查询第9条数据开始的2条数据。
注意:
1.limit a:查询前a条数据;limit a,b:查询(a+1)开始的b条数据,0为初始。
2.page方法,首先执行SELECT COUNT(*) AS total FROM user
,查询出总count,再执行SELECT id, username, password, phone, info, status, balance, create_time, update_time FROM user ORDER BY balance ASC, id ASC LIMIT 8,2
。因此,page中包含总条数total和总页数pages的信息。
3.此Page位于MyBatisPlus包下。