什么是分页(pagination)
例如,在数据库的某个表里有1000条数据,我们每次只显示100条数据,在第1页显示第0到第99条,在第2页显示第100到199条,依次类推,这就是分页。
分页可以分为物理分页和逻辑分页。物理分页是利用sql自带的limit去实现的,本身查询出来的数据是就算分页好的;逻辑分页是先查出来,然后利用代码去取需要的部分
分页的意义
分页确实有效,但它一定会加大系统的复杂度,但可否不分页呢?如果数据量少的话当然可以.但是对于企业信息系统来说数据量不会限制在一个小范围内.如果不顾一切的Select * from某个表,再将返回的数据一古脑的扔给客户,即使客户能够忍受成千上万足够让人眼花缭乱的表格式数据,繁忙的网络,紧张的服务器也会提出它们无声的抗议,甚至有时会以彻底的罢工作为终结.
使用Limit物理分页
-
接口
//分页 List<User> getUserByLimit(Map<String,Integer> map);
-
Mapper.xml
<!--结果集映射-->
<!--通过<resultMap>映射实体类属性名和表的字段名对应关系 -->
<resultMap type="com.kuang.pojo.User" id="UserMap">
<!-- 用id属性来映射主键字段 -->
<id property="id" column="id"/>
<!-- 用result属性来映射非主键字段 -->