spring aop中实现变更方法参数以及annotation
编程技术  /  houtizong 发布于 3年前   137
@Component@Aspectpublic class AopAnnotation { private Logger logger = LoggerFactory.getLogger(getClass()); @Pointcut("execution(public * com.*.*.*(..))") public void pointCut(){ } @Before(value = "pointCut()") public void before(){ logger.info("annotation, before################################"); } @Around("pointCut()") public void around(ProceedingJoinPoint joinPoint){ logger.info("annotation, around################################"); Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); try { joinPoint.proceed(); } catch (Throwable e) { } stopwatch.stop(); logger.info("annotation, ###################cost time: " + joinPoint.getThis().getClass().getName() + "\t" + stopwatch.elapsedMillis() + "(ms)"); } @AfterThrowing(pointcut = "pointCut()") public void aa(){ logger.info("error"); } public Verifier verifier;}
@Retention(RetentionPolicy.RUNTIME)@Target(ElementType.PARAMETER)public @interface Param { String value();}
@Around("sqlEscapePoint()") public Object sqlEscapeAdvice(ProceedingJoinPoint joinPoint) { logger.info("aroundSqlEscape, around################################"); Object[] objects = joinPoint.getArgs(); MethodSignature signature = (MethodSignature) joinPoint.getSignature(); Method method = signature.getMethod(); Annotation[][] annotations = method.getParameterAnnotations(); for (int i = 0; i < objects.length; i++) { Object tmpObject = objects[i]; boolean notEscape = false; if (annotations.length > 0) { for (Annotation annotation : annotations[i]) { if (annotation.annotationType() == NotEscapeSql.class) { notEscape = true; } } } if (notEscape) { continue; } objects[i] = EscapeUtil.escape(tmpObject, false, false, true); } Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); Object result = null; try { result = joinPoint.proceed(objects); } catch (Throwable e) { logger.error("sql escape", e); } stopwatch.stop(); logger.info("mapper cost time: " + joinPoint.getThis().getClass().getName() + "," + method.getName() + "\t" + stopwatch.elapsedMillis() + "(ms)"); return result; }
请勿发布不友善或者负能量的内容。与人为善,比聪明更重要!
技术博客集 - 网站简介:
前后端技术:
后端基于Hyperf2.1框架开发,前端使用Bootstrap可视化布局系统生成
网站主要作用:
1.编程技术分享及讨论交流,内置聊天系统;
2.测试交流框架问题,比如:Hyperf、Laravel、TP、beego;
3.本站数据是基于大数据采集等爬虫技术为基础助力分享知识,如有侵权请发邮件到站长邮箱,站长会尽快处理;
4.站长邮箱:[email protected];
文章归档
文章标签
友情链接