将 HandlerInterceptor 迁移到 Spring boot 2.6
Migrate HandlerInterceptor to Spring boot 2.6
我为 Spring 2.4
实现了这个旧代码
public class Interceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
........
return super.preHandle(request, response, handler);
}
}
我将代码迁移到 Spring 2.6:
public class Interceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
......................
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
我得到了 Cannot resolve method 'preHandle' in 'Object'
所以我将代码更改为 HandlerInterceptor.super.preHandle(request, response, handler);
这样编辑代码是否正确:HandlerInterceptor.super.preHandle(request, response, handler);
还是应该以其他方式编辑?
这应该是
public class Interceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
......................
return true;
}
}
注意方法 returns 一个布尔值。它告诉 Spring 进一步处理请求 (true) 或不 (false)。
preHandle()
在 HandlerInterceptor
中的默认实现只是 returns true
( https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html#preHandle-javax.servlet.http.HttpServletRequest-javax.servlet.http.HttpServletResponse-java.lang.Object- )
我为 Spring 2.4
实现了这个旧代码public class Interceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
........
return super.preHandle(request, response, handler);
}
}
我将代码迁移到 Spring 2.6:
public class Interceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
......................
return HandlerInterceptor.super.preHandle(request, response, handler);
}
}
我得到了 Cannot resolve method 'preHandle' in 'Object'
所以我将代码更改为 HandlerInterceptor.super.preHandle(request, response, handler);
这样编辑代码是否正确:HandlerInterceptor.super.preHandle(request, response, handler);
还是应该以其他方式编辑?
这应该是
public class Interceptor implements HandlerInterceptor {
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response,
Object handler) throws Exception {
......................
return true;
}
}
注意方法 returns 一个布尔值。它告诉 Spring 进一步处理请求 (true) 或不 (false)。
preHandle()
在 HandlerInterceptor
中的默认实现只是 returns true
( https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/web/servlet/HandlerInterceptor.html#preHandle-javax.servlet.http.HttpServletRequest-javax.servlet.http.HttpServletResponse-java.lang.Object- )