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 生 ...
随机推荐
- Arduino显示PM2.5
这代码一般都是复制过来,在小改下就行了 代码如下: #include <Wire.h> #include <LiquidCrystal_I2C.h> #include < ...
- 用MFC库函数AfxBeginThread()来创建线程
在进行多线程程序设计的时候,我们经常用到AfxBeginThread函数来启动一条线程该函数使用起来非常的简单方便,其定义如下: 1.函数原型 CWinThread* AfxBeginThread( ...
- 16 多校8 Rikka with Parenthesis II
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some mat ...
- ArcGIS中的数据连接问题——数据类型不统一
博主在研究空间数据分布的时候经常会用到 ArcGIS 进行空间数据可视化.但是有时候会由于数据类型不统一而无法将 csv 中的数据连接到底图上.比如在底图中的数据是字符串格式,而 csv 中是数字格式 ...
- 高级数据结构及应用 —— 使用 bitmap 进行字符串去重
bitmap 即为由单个元素为 boolean(0/1, 0 表示未出现,1 表示已经出现过)的数组. 如果C/C++ 没有原生的 boolean 类型,可以用 int 或 char 来作为 bitm ...
- nginx php
server { listen 443; server_name www.awkj.com; ssl on; ssl_certificate cert/214683879970617.pem; ssl ...
- Linux大文件分割splite
/********************************************************************** * Linux大文件分割splite * 说明: * 编 ...
- 使用rsync, 向另外一台服务器同步目录和文件的脚本
#!/bin/bash #亚特兰蒂斯-同步目录#定时任务ini_file="/usr/local/sunlight/conf/rsync-file.ini"target_ip=&q ...
- 修改select样式
CSS就可以解决,原理是将浏览器默认的下拉框样式清除,然后应用上自己的,再附一张向右对齐小箭头的图片即可. select { /*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/ ...
- PTA——输出各位数字
PTA 7-37 输出整数各位数字 方法1: #include <stdio.h> #define N 10000 int main(){ long n, temp; ; scanf(&q ...