-
增加依赖配置
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18<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>
-
增加配置
1
2
3
4
5
6
7
8<context:component-scan base-package="com.example.controller"/> <!-- 启动对@AspectJ注解的支持 --> <aop:aspectj-autoproxy/> <!--启动springmvc注解--> <mvc:annotation-driven content-negotiation-manager="contentNegotiationManager" />
-
增加注解
1
2
3
4
5
6@Target({ElementType.PARAMETER, ElementType.METHOD}) @Retention(RetentionPolicy.RUNTIME) @Documented public @interface EnablePaging { String value() default ""; }
-
增加AOP文件。 这里约定最后两个参数是pageNum 和pageSize
1 |
|
-
Controller层
1
2
3
4
5
6
7
8
9
10@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); }