Today, I was a little confused when I was writing interceptors in idea. I inherited handlerinterceptor without any errors. I always thought he would remind me to rewrite methods. As shown below
By checking the data, well, finally find the reason. First, go to the source code of the handlerinterceptor
interface
public interface HandlerInterceptor {
default boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
throws Exception {
return true;
}
default void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
@Nullable ModelAndView modelAndView) throws Exception {
}
default void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
@Nullable Exception ex) throws Exception {
}
}
Knock on the blackboard. Here’s the point
The above is the source code of the handlerinterceptor interface. You can see that in the higher version of spring webmvc jar package, the handlerinterceptor interface defines the default method, which is a new feature of JDK1.8. In other words, you can rewrite the methods in the interface without any error
So it doesn’t remind you to rewrite. You have to write it yourself
Similar Posts:
- Resource interpreted as Stylesheet but transferred with MIME type text/html: css not work
- How to Solve Error: Preflight response is not successful
- Error: there is already ‘RtController’ bean method [How to Solve]
- How to Solve Request processing failed; nested exception is java.lang.NullPointerException
- Error: Failed to start component [How to Solve]
- Access permission problem caused by object. Clone() method
- SpringMvc Error:java.lang.IllegalStateException
- Can’t create handler inside thread that has not called Looper.prepare()
- JavaWeb HttpServletRequest (How to Get Line, Header and Body)
- How to Solve Control reaches end of non-void block