zoukankan      html  css  js  c++  java
  • springmvc使用aop心得

    第一步:创建aop拦截类:

     1 @Component
     2 @Aspect
     3 public class ControllerSelectorInterceptor {
     7     @Before("execution(* com.my.test..*.*Controller.*(..))")  
     8     public void doBefore(JoinPoint jp) {
     9         StringBuffer method = new StringBuffer();
    10         method.append(jp.getTarget().getClass().getName()).append(".").append(jp.getSignature().getName());
    11         Object[] args = jp.getArgs();
    12         
    13         HttpServletRequest request = null;
    14         for(Object arg : args){
    15             if(arg instanceof HttpServletRequest){
    16                 request = (HttpServletRequest)arg;
    17             }
    18         }
    36     } 
    37 
    38      @After("execution(* com.my.test..*.*Controller.*(..))")
    39      public void doAfter(JoinPoint jp) {  
    40         Object[] args = jp.getArgs();
    41         StringBuffer method = new StringBuffer();
    42         method.append(jp.getTarget().getClass().getName()).append(".").append(jp.getSignature().getName());
    43         
    44         HttpServletRequest request = null;
    45         for(Object arg : args){
    46             if(arg instanceof HttpServletRequest){
    47                 request = (HttpServletRequest)arg;
    48             }
    49         }
    50         String account = request.getParameter("accountName");
    68      } 
    69 }

    第二步:在配置文件中加入以下配置:

    1     <aop:aspectj-autoproxy  proxy-target-class="true" />

    注:aop的详细介绍可以参考:http://www.360doc.com/content/11/1103/09/4280915_161262623.shtml

  • 相关阅读:
    链表-(1)
    爬虫(10-3)验证码图片识别
    爬虫10-2(多线程爬虫)
    分布式爬虫系统的架构(19)
    pipenv管理Python虚拟环境
    peewee-async集成到tornado
    Python3笔记051
    Python3笔记050
    Python3笔记049
    Python3笔记048
  • 原文地址:https://www.cnblogs.com/mihu/p/3122690.html
Copyright © 2011-2022 走看看