--Get the class name and method name of Controller executed by HandlerInterceptor
DemoInterceptor.java
public class DemoInterceptor extends HandlerInterceptorAdapter {
@Override
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
// (1)Skip if not HandlerMethod
//js or org.springframework.web.servlet.resource.Become a ResourceHttpRequestHandler
if (!HandlerMethod.class.isInstance(handler)) {
return true;
}
// (2)Cast handler to HandlerMethod
HandlerMethod handlerMethod = HandlerMethod.class.cast(handler);
// (3)Class name of Controller to be executed
String beanTypeName = handlerMethod.getBeanType().getName();
// (4)Method name of the method to be executed
String methodName = handlerMethod.getMethod().getName();
// (5)Short log message
//FQCN as follows#MethodName[Arguments]Can be obtained
// [example]
// case1) No arguments
// jp.gr.java_conf.pekokun.web.app.HelloController#say[0 args]
// case2) 1 argument
// jp.gr.java_conf.pekokun.web.app.HelloController#say[1 args]
String shortLogMessage = handlerMethod.getShortLogMessage();
// (6)You can also get method parameter information
// handlerMethod.getMethodParameters()...
return super.preHandle(request, response, handler);
}
end.
Recommended Posts