使用aop拦截请求返回信息
来源:互联网 发布:带windows系统的平板 编辑:程序博客网 时间:2024/06/03 17:34
@Pointcut(
“execution(public * com.mobcb.platform.service..controller...*(..)) ”
+ “@annotation(org.springframework.web.bind.annotation.RequestMapping)”)
public void doFilter() {
}
使用这个注解,将切点确定在某个包下的所有类中,然后@annotation注解将reqMapping注解确定,
将他在dofilter方法开面做操作
@Around(“doFilter()”)
spring aop中@Around @Before @After三个注解的区别@Before是在所拦截方法执行之前执行一段逻辑。@After 是在所拦截方法执行之后执行一段逻辑。@Around是可以同时在所拦截方法的前后执行一段逻辑。
[Java]代码
package com.itsoft.action;import org.springframework.context.support.ClassPathXmlApplicationContext;import org.springframework.stereotype.Controller;/** * * @author zxf * 演示aop测试类 */@Controllerpublic class UserAction { public void queryUsers(){ System.out.println("查询所有用户【all users list】"); } public static void main(String[] args) { ClassPathXmlApplicationContext ctx = new ClassPathXmlApplicationContext("application-aop.xml"); UserAction userAction = (UserAction)ctx.getBean("userAction"); userAction.queryUsers(); ctx.destroy(); }}
package com.itsoft;import org.aspectj.lang.ProceedingJoinPoint;import org.aspectj.lang.annotation.After;import org.aspectj.lang.annotation.Around;import org.aspectj.lang.annotation.Aspect;import org.aspectj.lang.annotation.Before;import org.aspectj.lang.annotation.Pointcut;import org.springframework.stereotype.Component;/** * * @author Administrator * 通过aop拦截后执行具体操作 */@Aspect@Componentpublic class LogIntercept { @Pointcut("execution(public * com.itsoft.action..*.*(..))") public void recordLog(){} @Before("recordLog()") public void before() { this.printLog("已经记录下操作日志@Before 方法执行前"); } @Around("recordLog()") public void around(ProceedingJoinPoint pjp) throws Throwable{ this.printLog("已经记录下操作日志@Around 方法执行前"); pjp.proceed(); this.printLog("已经记录下操作日志@Around 方法执行后"); } @After("recordLog()") public void after() { this.printLog("已经记录下操作日志@After 方法执行后"); } private void printLog(String str){ System.out.println(str); }}
阅读全文
0 0
- 使用aop拦截请求返回信息
- 使用 aop拦截 springMVC的controller并获取请求参数及返回结果
- AOP拦截常用请求内容
- Spring Boot AOP之对请求的参数入参与返回结果进行拦截处理
- Spring Mvc 公共Controller 使用拦截器注入请求信息
- 使用拦截器获取请求参数信息并写入日志
- 使用HttpClient发送请求并接收返回信息
- 使用Aop处理请求
- 使用spring aop拦截异常
- 拦截请求返回值的方法
- 给retrofit 的 添加okhttp的拦截器,可以让她显示 请求和返回的信息 ,便于查找错误
- Rx系列学习笔记_使用okhttp拦截器统一处理返回请求
- 使用拦截器来拦截请求handlerInterceptor
- php curl请求信息和返回信息
- 在Java中使用HttpURLConnection发送http客户端请求、服务器端返回信息、接受服务器端的信息
- 使用Fiddler拦截http请求
- axios全局请求参数设置,请求及返回拦截器
- SpringBoot 使用AOP处理请求
- Noip2013 Day2 T1 积木大赛(简单线性Dp)
- POJ 2388
- 高精度阶乘(递归版)
- highcharts饼图添加单击事件
- python实现单链表的翻转
- 使用aop拦截请求返回信息
- Spring4+MyBatis3整合配置文件详解
- 简易解说拉格朗日对偶(Lagrange duality)
- Java内存区域简述
- Java_23种设计模式(三)----- 结构型模式
- [leetcode]Median of Two Sorted Arrays
- 使用scanf()函数接收带空格的字符串
- 收银台程序
- Windows7 64位安装TensorFlow