当前位置: 首页 > news >正文

顺德定制网站设计王烨请叫我鬼差大人

顺德定制网站设计,王烨请叫我鬼差大人,哪里有做网络推广的,网站添加icp备案号Java 自定义注解#xff0c; 以及interface Target Retention Around Before After ProceedingJoinPoint JoinPoint 等用法 注解应用非常广泛#xff0c;我们自定义注解能简化开发各种各种业务 一、关键字解释 (1) 定义注解时#xff0c;关键字 interface 来表示注解类的类…Java 自定义注解 以及interface Target Retention Around Before After ProceedingJoinPoint JoinPoint 等用法 注解应用非常广泛我们自定义注解能简化开发各种各种业务 一、关键字解释 (1) 定义注解时关键字 interface 来表示注解类的类型 Target Retention 这两个具体值需要分析注解的应用场景来确定 对于“调用方法时打印入参和出参”的例子是在调用调用方法时则使用RetentionPolicy.RUNTIME 且作用于方法上则使用ElementType.METHOD (2) 实现注解时关键字 Before、After、AfterReturning 方法的入参是JoinPoint类型 Around 方法的入参是ProceedingJoinPoint类型 ProceedingJoinPoint继承了JoinPoint类型并扩展出了proceed()方法执行proceed()也就是执行原始的函数具体业务方法可以通过JoinPoint对象获取一些请求上的参数比如requestparms等 执行顺序 Around Before 被添加注解的方法业务执行 After AfterReturning 特别注意 注解中可以存在Around、Before 、After或、AfterReturning任意组合 注解中存在Around 也存在Before 、After或、AfterReturning时、会先执行Around 在Around中执行参数的ProceedingJoinPoint.proceed() 会触发Before 、“被添加注解的方法业务执行” 、After、AfterReturning的执行 在Around中不执行参数的ProceedingJoinPoint.proceed() 不会触发Before 、“被添加注解的方法业务执行”特别注意所以正常逻辑中ProceedingJoinPoint.proceed()都应该触发执行。 Around 的返回值应该为 “被添加注解的方法业务执行” 的返回值。通过获取Object bizData ProceedingJoinPoint.proceed(), 也可以对返回值加工再返回 三、代码实现 (1) 定义注解 package com.xxxxx.annotation;import java.lang.annotation.*;Target({ElementType.METHOD}) Retention(RetentionPolicy.RUNTIME) Documented Inherited public interface MethodParam {/*** 自定义方法 日志描述信息 可有可无** return*/String description() default ;/*** 自定义方法1 日志描述信息 可有可无** return*/String description1() default ;/*** 自定义方法2 日志描述信息 可有可无** return*/String description2() default ; } 其中description() description1() description2() 都是自定义方法相当于调用注解时的传参当业务需要就声明不需要就无需声明 (2) 实现注解 package com.xxxxx.annotation.annotationAspect;import com.xxxxx.annotation.MethodParam; import org.aspectj.lang.JoinPoint; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component;import java.lang.reflect.Method;Aspect Component public class MethodParamAspect {/*** 声明切点*/Pointcut(value annotation(com.xxxxx.annotation.MethodParam))public void doPointCut() {System.out.print(执行doPointCut \n);}/*** 调用方法前后执行* param joinPoint*/Around(value doPointCut())public Object doAround(ProceedingJoinPoint joinPoint) throws Throwable{System.out.print(执行doAround \n);//获取注解入参MethodSignature signature (MethodSignature) joinPoint.getSignature();Method method signature.getMethod();MethodParam methodParamNew method.getAnnotation(MethodParam.class);String description methodParamNew.description();String description1 methodParamNew.description1();String description2 methodParamNew.description2();//被添加注解的方法业务执行Object bizData joinPoint.proceed();//处理其他业务return bizData;}/*** 调用方法之【前】执行* param joinPoint*/Before(value doPointCut())public void doBefore(JoinPoint joinPoint){System.out.print(执行doBefore \n);//处理其他业务}/**** 调用方法之【后】执行** param joinPoint*/After(value doPointCut())public void doAfter(JoinPoint joinPoint){System.out.print(执行doAfter \n);//处理其他业务}/**** After执行之【后】执行** param joinPoint* param res 具体业务的返回值 (可有可无)*/AfterReturning(value doPointCut(),returning res)public void doAfterReturning(JoinPoint joinPoint, String res){System.out.print(执行doAfterReturning \n);//处理其他业务} } (3) 使用注解 package com.xxxxx.component;import com.xxxxx.annotation.MethodParam; import org.springframework.stereotype.Component; import java.util.Random;Component public class OrderComponent {MethodParam(description aaa, description1 bbb, description2 ccc)public String testAnnotation(String val1, String val2){String aa val1.concat(val2).concat(String.valueOf(String.format(%04d,new Random().nextInt(9999))));System.out.print(aa \n);return aa;} }
http://wiki.neutronadmin.com/news/297398/

相关文章:

  • 商业中心 网站建设微网站建设是什么
  • wordpress回收站+恢复国外服装图案设计网站
  • 优化网站界面的工具手机版网站制作费用
  • 上海网站建设上海网站制作舟山 做企业网站
  • 个人简介网站源码wordpress头像上传
  • 智云鸟网站建设o2o是什么意思啊
  • 网站建设 全包 制作品牌营销活动策划方案
  • 网站建设合同图片上海ktv最新通知
  • 做啤酒最全的网站wordpress当前导航菜单
  • json网站开发台州网站建设选浙江华企
  • 自适应式网站长沙专业竞价优化公司
  • 做自媒体与做网站公司做网站的价格
  • 网站做百度推广建设企业和建筑企业
  • 胖哥网站的建设目标网站建设的开发工具
  • 安踏网站建设策划方案wordpress图创
  • 北京网站制作很好 乐云践新陕西省住房和城乡建设厅官网证件
  • 银川建设厅网站wordpress响应式播放器
  • 昆山做网站的公司有哪些wordpress page
  • asp相册网站源码手机网站 微网站
  • 企业网站开发制作合同新手学做网站要多久
  • 移动网站mipwordpress中国网站模板
  • 揭秘低价网站建设危害仿网站源码是怎么弄的
  • 高端网站制作多少钱优秀的浏览器主页
  • 速卖通网站怎样做店面的二维码自己做的网站怎么发布到网上
  • 三大框架网站开发网页qq登录保护不让用
  • 深圳网站开发公司h5wordpress时区设置
  • 外卖网站建设方案书昆山市网站建设
  • flask做网站工具重庆网站制作设计获客
  • 定制网站哪个好白和黑人做网站
  • 网页设计结课报告关键词优化seo多少钱一年