app调用后台接口需要对其token及设备码进行检查,不匹对则拦截此次请求。公司要求做一个拦截器对app的请求进行检查,Spring框架自带一个HandlerInterceptor,我们只要实现这个接口就可以完成拦截器的制作。
1.在Spirng配置文件中添加如下代码:
<!-- APP端验证Token拦截器配置 -->
<mvc:interceptors>
<mvc:interceptor>
<mvc:mapping path="/*/*" />
<bean class="idcrep.web.controller.TokenVerificationInterceptor">
<property name="interceptUrls">
<list>
<!--需要拦截的app接口 -->
<value>/sign</value>
<value>/carInspect</value>
<value>/message</value>
<value>/question</value>
<value>/task</value>
</list>