标题:spring mvc 中如何使用aop拦截到@controller?
只看楼主
xzqzhazha
Rank: 1
来 自:四川成都
等 级:新手上路
帖 子:16
专家分:2
注 册:2010-8-31
结帖率:20%
已结贴  问题点数:15 回复次数:2 
spring mvc 中如何使用aop拦截到@controller?
spring mvc 中@controller注解在初始化时被代理,请教一下如何使用aop拦截到@controller,有说实现HanlderInterceptorAdapter的,请具体指教一下,新人上路多多关照...
搜索更多相关主题的帖子: 如何 spring 
2013-06-18 10:24
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
得分:0 
是要使用拦截器吗?
2013-06-18 10:30
hhwz
Rank: 13Rank: 13Rank: 13Rank: 13
等 级:贵宾
威 望:87
帖 子:687
专家分:4502
注 册:2011-5-22
得分:15 
程序代码:
//配置你的拦截器的bean
 <!-- 日志拦截器 -->
  <bean id="loggerInterception" class="web.interceptor.LoggerInterception" />//class填写地址

<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping">
        <property name="interceptors">
            <list>
                <ref bean="loggerInterception"/>
            </list>
        </property>
    </bean>

//------------------------分割线-----------------------

public class LoggerInterception extends HandlerInterceptorAdapter{
    private static Log log = Log.getLog(LoggerInterception.class);
    @Override
    public void afterCompletion(HttpServletRequest request,
            HttpServletResponse response, Object handler, Exception ex)
            throws Exception {
        // TODO Auto-generated method stub
        super.afterCompletion(request, response, handler, ex);
    }

    @Override
    public void postHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {
        log.info("modelAndView:"+modelAndView);
        super.postHandle(request, response, handler, modelAndView);
    }

    @Override
    public boolean preHandle(HttpServletRequest request,
            HttpServletResponse response, Object handler) throws Exception {
        log.info("request:"+request.getRequestURI());
      
        return super.preHandle(request, response, handler);
    }

}
2013-06-18 10:37



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-415448-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.513038 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved