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

  • 相关阅读:
    HDU1007
    DFA
    netstat
    Sangfor
    JS 基础逻辑关系
    正则表达式
    JS中的DOM
    HTML、CSS、JS面试题
    JS作用域和作用域链
    JS String与正则表达式
  • 原文地址:https://www.cnblogs.com/mihu/p/3122690.html
Copyright © 2011-2022 走看看