Spring 配置拦截器 能配置只拦截一个连接的 GET 请求,不拦截 POST 请求可以吗?

xml    <!-- 配置拦截器 -->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/list" />
            <mvc:mapping path="/list/" />
            <bean class="com.web.interceptor.AppInterceptor"></bean>
        </mvc:interceptor>
    </mvc:interceptors>

如果我只想拦截 /list/GET 请求可以吗?

阅读 17.8k
3 个回答

配置时把要处理的请求类型传递给 AppInterceptor, 然后在 AppInterceptor 的preHandle方法里直接判断是否处理。

获取当前请求类型使用 String method = request.getMethod();

指定具体的方法名,然后get方法和post方法用方法名区分开

springmvc可以的,可以通过注解窄化拦截的请求。
例如:
@RequestMapping(value="/list", method = {RequestMethod.GET})

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题