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
请求可以吗?
指定具体的方法名,然后get方法和post方法用方法名区分开
配置时把要处理的请求类型传递给 AppInterceptor, 然后在 AppInterceptor 的preHandle方法里直接判断是否处理。
获取当前请求类型使用 String method = request.getMethod();
springmvc可以的,可以通过注解窄化拦截的请求。
例如:
@RequestMapping(value="/list", method = {RequestMethod.GET})