1、增加依赖配置

    <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
<version>1.6.11</version>
</dependency> <dependency>
<groupId>org.aspectj</groupId>
<artifactId>aspectjrt</artifactId>
<version>1.6.11</version>
</dependency>

  增加pagehelper

    <dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>4.1.0</version>
</dependency>

  

2、增加配置

 <context:component-scan base-package="com.example.controller"/>

    <!-- 启动对@AspectJ注解的支持 -->
<aop:aspectj-autoproxy/> <!--启动springmvc注解-->
<mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />

  

3、增加注解

@Target({ElementType.PARAMETER, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface EnablePaging {
String value() default "";
}

  

4、 增加AOP文件。

这里约定最后两个参数是pageNum 和pageSize

@Aspect
@Component
@Slf4j
public class PageAop { @Pointcut("@annotation(com.example.annotation.EnablePaging)")
public void serviceAspect(){
log.info("serviceAspect");
} @Before("serviceAspect()")
public void doBefore(JoinPoint joinPoint) {
log.info("doBefore");
} @Around(value = "serviceAspect()")
public Object doAround(ProceedingJoinPoint point) throws Throwable{
log.info("doAround ");
Object[] args = point.getArgs();
Integer pageNum = 1;
Integer pageSize = 10;
if(args.length >= 2){
pageNum = (Integer)args[args.length -2];
pageSize = (Integer)args[args.length - 1];
}
PageHelper.startPage(pageNum, pageSize);
return point.proceed(args);
} }

5. Controller层

  @RequestMapping(value = "queryLogs")
@EnablePaging
@ResponseBody
public ServerResponse<PageInfo> queryLogs(HttpServletResponse response,
@RequestParam(value = "pageNum",defaultValue = "1") int pageNum,
@RequestParam(value = "pageSize",defaultValue = "10")int pageSize){
List<Log> list = iLogService.queryList(pageNum, pageSize);
PageInfo pageInfo = new PageInfo(list);
return ServerResponse.createBySuccess(pageInfo);
}

  

  

Spring AOP + PageHelper分页的更多相关文章

  1. Spring 中PageHelper分页插件使用

    1.增加pagehelper <!-- mybatis pager --> <dependency> <groupId>com.github.pagehelper& ...

  2. 关于Spring+mybatis+PageHelper分页插件PageHelper的使用策略

    把插件jar包导入项目(具体上篇有介绍http://blog.csdn.net/qq_33624284/article/details/72821811) spring-mybatis.xml文件中配 ...

  3. spring boot 整合pagehelper分页插件

    Spring Boot 整合pagehelper分页插件 测试环境: spring boot  版本 2.0.0.M7 mybatis starter 版本  1.3.1 jdk 1.8 ------ ...

  4. 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法

    spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...

  5. Spring Boot+Mybatis+Pagehelper分页

    Spring Boot 集成MyBatis和Pagehelper分页插件 mybatis-spring-boot-starter依赖树如下: pom配置 <project xmlns=" ...

  6. Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程

    Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...

  7. PageHelper分页实战(SSM整合)

    步骤一:引入SSM相关的jar包,包列表如下: 步骤二:创建或修改配置文件,配置文件清单如下: applicationContext.xml <?xml version="1.0&qu ...

  8. Spring AOP中级——应用场景

    在<Spring AOP初级——入门及简单应用>中对AOP作了简要的介绍,以及一些专业术语的解释,同时写了一个简单的Spring AOPdemo.本文将继续探讨Spring AOP在实际场 ...

  9. Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件

    前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...

随机推荐

  1. restful接口设计规范总结

    这篇 文章主要是借鉴他人,但是自己很想总结出一套规范,以供向我这样的新手使用,用来规范代码,如果有什么好的提议,请不吝赐教,本篇文章长期更新! 一.重要概念: REST,即Representation ...

  2. LeetCode--219、268、283、414、448 Array(Easy)

    219. Contains Duplicate II Given an array of integers and an integer k, find out whether there are t ...

  3. 微软Power BI 每月功能更新系列——8月Power BI 新功能学习

    Power BI Desktop 8月新功能摘要 Power BI 产品八月发布的新版本又刷新了大家所期待的一些功能,它可以更方便的解决我们从用户那里听到的一些最重要的请求:其中最令人兴奋的是我们的导 ...

  4. 后门技术(HOOK篇)之DT_RPATH

    0x01 GNU ld.so动态库搜索路径 参考材料:https://en.wikipedia.org/wiki/Rpath 下面介绍GNU ld.so加载动态库的先后顺序: LD_PRELOAD环境 ...

  5. [LeetCode&Python] Problem 171. Excel Sheet Column Number

    Given a column title as appear in an Excel sheet, return its corresponding column number. For exampl ...

  6. [Data Structure] An Algorithm for Matching Delimiters

    An important task when processing arithmetic expressions is to mach delimiters. We can use Stack to ...

  7. C++学习(十)(C语言部分)之 分支语句

    #include<stdio.h> // std 标准  io ---->  input  output  输入 输出  printf scanf getchar ...... #i ...

  8. 【HDOJ1051】【排序+LIS】【贪心】

    http://acm.hdu.edu.cn/showproblem.php?pid=1051 Wooden Sticks Time Limit: 2000/1000 MS (Java/Others)  ...

  9. 利用 httpmodule 强制所有页面使用同一基类

    public class OMSPageChecker : IHttpModule { public void Dispose() { } public void Init(HttpApplicati ...

  10. diskcache

    DiskCache: Disk Backed Cache DiskCache is an Apache2 licensed disk and file backed cache library, wr ...