如何使用SpringMVC拦截器的preHandle方法获取当前执行的目标方法
如访问http://localhost:8080/courses/testEncoding在拦截器中可以获取到testEncoding方法
ps:可以使用HandlerMethod获取到该方法,但是原本正常运行的程序会报错:
java.lang.ClassCastException: org.springframework.web.servlet.resource.ResourceHttpRequestHandler cannot be cast to org.springframework.web.method.HandlerMethod
页面可以显示,但是并无CSS样式。。删除HandlerMethod语句就可以正常运行
@Override
public boolean preHandle(HttpServletRequest arg0, HttpServletResponse arg1, Object arg2) throws Exception {
System.out.println("执行preHandle");
HandlerMethod hm = (HandlerMethod) arg2;
System.out.println("当前执行的对象是"+hm.getMethod());
return true;
}