zoukankan      html  css  js  c++  java
  • 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

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

      

  • 相关阅读:
    BZOJ 2120 数颜色
    BZOJ 3289 Mato的文件管理
    BZOJ 2038 小Z的袜子
    BZOJ 1878 HH的项链
    洛谷P2709 小B的询问
    6491: Daydream
    问题 L: An Invisible Hand
    HDU-2177 取(2堆)石子游戏 (威佐夫博奕)
    (POJ-3279)Fliptile (dfs经典---也可以枚举)
    问题 J: Palindromic Password ( 2018组队训练赛第十五场) (简单模拟)
  • 原文地址:https://www.cnblogs.com/LWLDD/p/8694519.html
Copyright © 2011-2022 走看看