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. 去掉 input type="number" 在浏览器中遗留的图标样式

    input::-webkit-outer-spin-button,input::-webkit-inner-spin-button{  /* chrome */     -webkit-appeara ...

  2. CentOS7+Nginx配置Tomcat负载均衡环境

    1.准备两个Tomcat 配置两个Tomcat一个端口是8080另外一个端口是8081,分别在webapps下面添加一个测试用的web项目,修改index.jsp文件,8080端口的index.jsp ...

  3. linux 将一个文件分解成多个不同名文件

    1.通过c直接实现 #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include & ...

  4. ajax跨域(No 'Access-Control-Allow-Origin' header is present on the requested resource)

    问题 在某域名下使用Ajax向另一个域名下的页面请求数据,会遇到跨域问题.另一个域名必须在response中添加 Access-Control-Allow-Origin 的header,才能让前者成功 ...

  5. grep命令相关用法

    grep命令相关参数: -i:忽略大小写 --color:高亮显示匹配到的信息 -v:反向查找,没匹配到的行显示出来 -o:只显示被模式匹配到的串本身 正则表达式: .*:任意长度的任意字符,贪婪模式 ...

  6. C高级第三次作业

    C高级第三次作业(1) 6-1 输出月份英文名 1.设计思路 (1)算法: 第一步:定义整型变量n,字符指针s,输入一个数赋给n. 第二步:调用函数getmonth将值赋给s. 第三步:在函数getm ...

  7. 基于C#利用ffmpeg提取视频帧

    利用ffmepg提取视频帧实际上是利用C#调用ffmepg命令行进行处理对应的视频,然后输出出视频帧 GetPicFromVideo("); static public string Get ...

  8. PWA需要的技术

    1 Manifest                      https://developer.mozilla.org/zh-CN/docs/Web/Manifest 2 Service Work ...

  9. 环境变量、cp、mv、cat 等命令

    1.环境变量: PATH 个人理解 环境变量,即是所有命令文件所存放的目录,或是人为的定义的目录,(命令文件所存放的目录,当输入一个命令的时候,系统会自动找到且不报错,并不需要输入绝对路径,来运行相关 ...

  10. 实验吧—隐写术——WP之 SB!SB!SB!

    我们先打开解题链接,里面是一张愤怒的小鸟里的小猪~ 既然这是隐写题,那么肯定要把图片下载下来进行分析咯~ 下载下来之后,我们看到题目中提示:LSB 什么是LSB? LSB(Least Signific ...