Spring AOP + PageHelper分页
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分页的更多相关文章
- Spring 中PageHelper分页插件使用
1.增加pagehelper <!-- mybatis pager --> <dependency> <groupId>com.github.pagehelper& ...
- 关于Spring+mybatis+PageHelper分页插件PageHelper的使用策略
把插件jar包导入项目(具体上篇有介绍http://blog.csdn.net/qq_33624284/article/details/72821811) spring-mybatis.xml文件中配 ...
- spring boot 整合pagehelper分页插件
Spring Boot 整合pagehelper分页插件 测试环境: spring boot 版本 2.0.0.M7 mybatis starter 版本 1.3.1 jdk 1.8 ------ ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- Spring Boot+Mybatis+Pagehelper分页
Spring Boot 集成MyBatis和Pagehelper分页插件 mybatis-spring-boot-starter依赖树如下: pom配置 <project xmlns=" ...
- Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程
Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...
- PageHelper分页实战(SSM整合)
步骤一:引入SSM相关的jar包,包列表如下: 步骤二:创建或修改配置文件,配置文件清单如下: applicationContext.xml <?xml version="1.0&qu ...
- Spring AOP中级——应用场景
在<Spring AOP初级——入门及简单应用>中对AOP作了简要的介绍,以及一些专业术语的解释,同时写了一个简单的Spring AOPdemo.本文将继续探讨Spring AOP在实际场 ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
随机推荐
- ES6 对象的扩展 Object.is()
ES5 比较两个值是否相等,只有两个运算符:相等运算符(==)和严格相等运算符(===).它们都有缺点,前者会自动转换数据类型,后者的NaN不等于自身,以及+0等于-0. ES6 提出“Same-va ...
- MySQL常见建表选项及约束
阅读目录---MySQL常见的建表选项及约束: 1.create table选项 1.指定列选项:default.comment 2.指定表选项:engine.auto_increment.comme ...
- lintcode 刷题 by python 部分链表题总结(2)
本篇博客对最近做的链表的算法题做个简单的小结,主要描述题目和提供解题思路,具体代码见我的 github:https://github.com/MUSK1881/lintcode-by-python 3 ...
- Python学习笔记第二十周
目录: 一.ORM 1.查询补充 备注:forloop.counter介绍 二.Ajax 三.ORM多对多操作 内容: 一.ORM 1.查询补充: 1.models.USR.objects.all() ...
- s21day01 python笔记
s21day01 python笔记 一.计算机基础 计算机的初步认识 用户:人 软件:QQ.浏览器等 解释器/编译器/虚拟机:java解释器.python解释器等 操作系统 硬件:CPU.内存.硬盘. ...
- day 020 常用模块02
主要内容: 什么是序列化 pickle shelve json configparser(模块) 一 序列化 我们在存储数据或者网络传输数据的时候,需要对我们的对象进行处理,把对象处理成方便存储和 传 ...
- RESTful规范(一)
一.学习restframework之前准备 1.json格式若想展示中文,需要ensure_ascii=False import json dic={'name':'你好'} print(json.d ...
- (9)模板层 - templates(模板语言、语法、取值、过滤器、变量的使用)
django的模板语言:DTL 模板语言的变量传入 这个是标签 {{ 变量名 }} {{ 变量名 }} #模板语言的替换可以在模板中的任意位置生效 PS:通过 . 可以做深度查询 模板语言的过滤器 ...
- Python的文件处理
引子 1.问题:给你一个文件 "兼职白领学生空姐模特护士联系方式.txt" ,如何查看内容? 答: 安装文本编辑器软件 选中右键,利用文本编辑器软件打开 查看 or 写入 保存,关 ...
- hdu3336 Count the string 扩展KMP
It is well known that AekdyCoin is good at string problems as well as number theory problems. When g ...