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 生 ...
随机推荐
- linux 部署之路 修行不够全靠悟
考虑到很多孩子不会Linux或Mysql,所以我这里提示一下, 这篇教程里 "有多行代码" 的是给你展示结果的,不用你敲 只有一行的才是要你自己敲进去的. 1.首先更新一下仓库 ...
- IOS safari 浏览器 时间乱码(ios时间显示NaN) 问题解决
问题一: 项目中遇到一个关于日期时间在ios中乱码在安卓中安然无恙的问题,焦躁了半天 问题如上图,通过用户选择的时间和当天的天数相加然后在ios上就是乱码 这个界面运用了日期类型的计算,当我们用Jav ...
- socket 聊天室实现
server #include <stdio.h> #include <sys/types.h> /* See NOTES */ #include <sys/socket ...
- TensorRT caffemodel serialize
1.TensorRT的需要的文件 需要的基本文件(不是必须的) 1>网络结构文件(deploy.prototxt) 2>训练的权重模型(net.caffemodel) TensorRT 2 ...
- CodeForces - 1101D:GCD Counting (树分治)
You are given a tree consisting of n vertices. A number is written on each vertex; the number on ver ...
- hdoj-1068(二分图的最小点覆盖)
题目 1 问题转化: 求二分图最小点覆盖(覆盖所有的边) 2 问题的解决: 二分图最小点覆盖==其最大匹配数 3 证明: 链接 =#include <bits/stdc++.h> ...
- 最长公共子序列与最长公共字串 (dp)转载http://blog.csdn.net/u012102306/article/details/53184446
1. 问题描述 子串应该比较好理解,至于什么是子序列,这里给出一个例子:有两个母串 cnblogs belong 比如序列bo, bg, lg在母串cnblogs与belong中都出现过并且出现顺序与 ...
- EasyUI datagrid combox onchange 五
$("#sTwo").combobox({ onChange: function (n,o) { n改变后,o改变前 }
- MySQL数据库一
MySQL的基本命令: 进入数据库: mysql -u [username] -p[password] (注:-u 和 用户名之间可以有空格 -p和password之间无空格) mysql -u ...
- gcd(1,n)+gcd(2,n)....gcd(n-1,n); Uva11426
#include<bits/stdc++.h> #define int long long using namespace std; ; int phi[maxn]; int prime[ ...