请教下大佬们, spring mvc 添加过滤器后 post 参数无法自动注入问题
source link: https://www.v2ex.com/t/864848
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
第 1 条附言 · 1 小时 56 分钟前
qinxi 2 小时 32 分钟前 参考 CommonsRequestLoggingFilter核心由 AbstractRequestLoggingFilter 提供
|
LeegoYih 2 小时 28 分钟前
用拦截器吧
新建一个类,实现`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 容器中:
```
@Configuration
public class FooConfiguration implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new FooHandlerInterceptor()).addPathPatterns("/**");
}
}
```
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK