请教下大佬们, spring mvc 添加过滤器后 post 参数无法自动注入问题
收藏(0)
分享
相关标签:
注意:本文归作者所有,未经作者允许,不得转载
-
2022年7月8日 02:58
用拦截器吧
新建一个类,实现`HandlerInterceptor`接口:
```java
public class FooHandlerInterceptor implements HandlerInterceptor {
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
// TODO
return true;
}
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
// TODO
}
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
// TODO
}
}
```
新建一个配置类,实现`WebMvcConfigurer`接口,重写`addInterceptors`方法,将拦截器注册到 Spring MVC 容器中:
```
public class FooConfiguration implements WebMvcConfigurer {
@
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new FooHandlerInterceptor()).addPathPatterns("/**");
}
}
```
0
0
-
2022年7月8日 02:58
贴代码
0
0
-
2022年7月8日 02:58
有意思 我看看我们咋个解决得
0
0
-
2022年7月8日 03:28
0
0