The interface method is not rewritten, and the idea does not report an error.

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: