如何在Spring MVC中自定义注解
1个回答
2014-11-30
展开全部
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler) throws Exception {
try{
Method m = AnnotationMethodHandlerAdapter.class.getDeclaredMethod("getMethodResolver", Object.class);
m.setAccessible(true);
HandlerMethodResolver resolver = (HandlerMethodResolver)m.invoke(annotationMethodHandlerAdapter, handler);
Method resolveHandlerMethod = resolver.getClass().getMethod("resolveHandlerMethod", HttpServletRequest.class);
resolveHandlerMethod.setAccessible(true);
Method currentMethod = (Method)resolveHandlerMethod.invoke(resolver, request);
AccessPermission AccessPermission = currentMethod.getAnnotation(AccessPermission.class);
System.out.println(currentMethod.getName() + "="+AccessPermission);
//获取到自定义注解AccessPermission,处理后续逻辑
}catch(Exception e){
e.printStackTrace();
}
}
HttpServletResponse response, Object handler) throws Exception {
try{
Method m = AnnotationMethodHandlerAdapter.class.getDeclaredMethod("getMethodResolver", Object.class);
m.setAccessible(true);
HandlerMethodResolver resolver = (HandlerMethodResolver)m.invoke(annotationMethodHandlerAdapter, handler);
Method resolveHandlerMethod = resolver.getClass().getMethod("resolveHandlerMethod", HttpServletRequest.class);
resolveHandlerMethod.setAccessible(true);
Method currentMethod = (Method)resolveHandlerMethod.invoke(resolver, request);
AccessPermission AccessPermission = currentMethod.getAnnotation(AccessPermission.class);
System.out.println(currentMethod.getName() + "="+AccessPermission);
//获取到自定义注解AccessPermission,处理后续逻辑
}catch(Exception e){
e.printStackTrace();
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询