pagehelper源码分析

pagehelper不用说,只要是用过的就会爱上他!
Maven依赖:

		<!-- 分页 -->
		<dependency>
			<groupId>com.github.pagehelper</groupId>
			<artifactId>pagehelper-spring-boot-starter</artifactId>
			<version>1.2.5</version>
		</dependency>

controller调用,我这里用的thymeleaf模板

	@GetMapping(value = "")
	public String index(@RequestParam(value = "page", defaultValue = "1") int page,
			@RequestParam(value = "limit", defaultValue = "8") int limit, HttpServletRequest request) {
		PageHelper.startPage(page, limit);
		List<Article> list = modifyService.getArticleList();
		PageInfo<Article> pageInfo = new PageInfo<>(list);
		request.setAttribute("pageInfo", pageInfo);
		return "admin/article_list";
	}

那么来到了pagehelper源码:
根据源码,这里就分析一下:

    //跳过 count 和 分页查询,当项目存在多个分页插件、设置默认的 count 列为空时
   boolean skip(MappedStatement ms, Object parameterObject, RowBounds rowBounds);
//执行分页前,返回 true 会进行 count 查询,false 会继续下面的 beforePage 判断
boolean beforeCount(MappedStatement ms, Object parameterObject, RowBounds rowBounds);
    //生成 count 查询 sql
    String getCountSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey countKey);
   // 执行完 count 查询后
   // count:查询结果总数
   // parameterObject:接口参数
   // rowBounds:分页参数
   // 返回值为true时继续分页查询,false 直接返回
 
   boolean afterCount(long count, Object parameterObject, RowBounds rowBounds);
  //处理查询参数对象
   ct processParameterObject(MappedStatement ms, Object parameterObject, BoundSql boundSql, CacheKey pageKey);
    // 执行分页前,返回 true 会进行分页查询,false 会返回默认查询结果
    boolean beforePage(MappedStatement ms, Object parameterObject, RowBounds rowBounds);
    // 生成分页查询 sql,这里就不乖=怪为啥我们总是能看见一系列的SQL语句输出:limit ?,?,但是我们并没有写这样的SQL语句吧
    String getPageSql(MappedStatement ms, BoundSql boundSql, Object parameterObject, RowBounds rowBounds, CacheKey pageKey);
   //分页查询后,处理分页结果,拦截器中直接 return 该方法的返回值
    Object afterPage(List pageList, Object parameterObject, RowBounds rowBounds);
	 //完成所有任务后
	void afterAll();
	 //给pagehelper设置参数
     //拿到properties里面的插件属性
    void setProperties(Properties properties);
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值