spring拦截器

Posted 老邱2

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring拦截器相关的知识,希望对你有一定的参考价值。


<!--     将拦截所有请求 -->
<!--     <mvc:interceptors> -->
<!--         <bean class="com.SpringInter"></bean> -->
<!--     </mvc:interceptors> -->
    
    
<!--     针对具体路径进行拦截 -->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/test"/>
            <bean class="com.SpringInter"></bean>
        </mvc:interceptor>
    </mvc:interceptors>
package com;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class SpringInter implements HandlerInterceptor {

    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
            throws Exception {
        String url=request.getRequestURI();
        System.out.println(url);
        return true;
    }

    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
            ModelAndView modelAndView) throws Exception {

    }

    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
            throws Exception {

    }

}

 

以上是关于spring拦截器的主要内容,如果未能解决你的问题,请参考以下文章

spring---transaction---源代码分析(事务的拦截器TransactionInterceptor)

Spring aop 拦截不到Dao

spring方法拦截实例

spring-bootspring-boot项目中,通过thymleaf实现登录功能,这里是一个登录拦截器的参考代码

spring-boot 拦截器不拦截

spring事物源码分析篇三:业务代码的执行--事物增强器