• spring mvc 拦截器


    拦截器类  实现 

     HandlerInterceptor 接口   先走 1    在走方法  在走  2   最后 3
    public class jf implements HandlerInterceptor {
        public boolean preHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o) throws Exception {
            System.out.println("11111111");
            return true;
        }
    
        public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
            System.out.println("22222222222");
        }
    
        public void afterCompletion(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, Exception e) throws Exception {
            System.out.println("333333333333");
        }
    }

    xml的配置文件  

     <mvc:interceptors>
    
    
             <mvc:interceptor>
                 <mvc:mapping path="/**"/>
                 <bean class="springmmv.peg.jke.jf"></bean>
    
             </mvc:interceptor>
    
    
        </mvc:interceptors>

      

    class就是那个类  /**   所有   如果还有其他的拦截器    在加一个 

       <mvc:interceptor> 节点就行 ,里面配上  path class  就行    

    测试方法就是一个普通的控制器方法

    也给以下
    @Controller
    public class tec {
    
    
        @RequestMapping("/first")
        public String hj(){
    
            System.out.println("asaaaaaaaa");
            return "ax";
    
        }
    
    }

         ax是有了试图解析器后这么写  

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
            <property name="prefix" value="/"></property>
            <property name="suffix" value=".jsp"></property>
        </bean>

       运行结果给你们以下 

      

    11111111
    asaaaaaaaa
    22222222222
    333333333333

      好像就是这么一点基础的概念  , 。。。。。

      

  • 相关阅读:
    ACM成长之路
    洛谷P1047 校门外的树
    洛谷P1046 陶陶摘苹果
    2017 ACM-ICPC 亚洲区(南宁赛区)网络赛 F题
    图论:POJ2186-Popular Cows (求强连通分量)
    DFS:POJ1562-Oil Deposits(求连通块个数)
    DFS:POJ3620-Avoid The Lakes(求最基本的联通块)
    map函数的应用:UVa156-Ananagrams
    set的应用:UVa10815-Andy's First Dictionary
    水题:UVa253-Cube painting
  • 原文地址:https://www.cnblogs.com/LWLDD/p/8694519.html
Copyright © 2020-2023  润新知