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

塑胶制品东莞网站建设软件公司 网站建设费分录

塑胶制品东莞网站建设,软件公司 网站建设费分录,小程序源码1200套,php做网站浏览量学习的最大理由是想摆脱平庸#xff0c;早一天就多一份人生的精彩#xff1b;迟一天就多一天平庸的困扰。各位小伙伴#xff0c;如果您#xff1a; 想系统/深入学习某技术知识点… 一个人摸索学习很难坚持#xff0c;想组团高效学习… 想写博客但无从下手#xff0c;急需… 学习的最大理由是想摆脱平庸早一天就多一份人生的精彩迟一天就多一天平庸的困扰。各位小伙伴如果您 想系统/深入学习某技术知识点… 一个人摸索学习很难坚持想组团高效学习… 想写博客但无从下手急需写作干货注入能量… 热爱写作愿意让自己成为更好的人… 文章目录 前言一、基于注解的AOP1、技术说明2、准备工作3、创建切面类并配置4、各种通知5、切入点表达式语法6、重用切入点表达式7、获取通知的相关信息8、环绕通知9、切面的优先级 二、基于XML的AOP1、准备工作2、实现 总结 前言 一、基于注解的AOP 1、技术说明 2、准备工作 3、创建切面类并配置 4、各种通知 5、切入点表达式语法 6、重用切入点表达式 7、获取通知的相关信息 8、环绕通知 9、切面的优先级 二、基于XML的AOP 1、准备工作 2、实现 一、基于注解的AOP 1、技术说明 动态代理分为JDK动态代理和cglib动态代理当目标类有接口的情况使用JDK动态代理和cglib动态代理没有接口时只能使用cglib动态代理JDK动态代理动态生成的代理类会在com.sun.proxy包下类名为$proxy1和目标类实现相同的接口cglib动态代理动态生成的代理类会和目标在在相同的包下会继承目标类动态代理InvocationHandlerJDK原生的实现方式需要被代理的目标类必须实现接口。因为这个技术要求代理对象和目标对象实现同样的接口兄弟两个拜把子模式。cglib通过继承被代理的目标类认干爹模式实现代理所以不需要目标类实现接口。AspectJ是AOP思想的一种实现。本质上是静态代理将代理逻辑“织入”被代理的目标类编译得到的字节码文件所以最终效果是动态的。weaver就是织入器。Spring只是借用了AspectJ中的注解。 2、准备工作 ①添加依赖 在IOC所需依赖基础上再加入下面依赖即可 dependencies!--spring context依赖--!--当你引入Spring Context依赖之后表示将Spring的基础依赖引入了--dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion6.0.2/version/dependency!--spring aop依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-aop/artifactIdversion6.0.2/version/dependency!--spring aspects依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-aspects/artifactIdversion6.0.2/version/dependency!--junit5测试--dependencygroupIdorg.junit.jupiter/groupIdartifactIdjunit-jupiter-api/artifactIdversion5.3.1/version/dependency!--log4j2的依赖--dependencygroupIdorg.apache.logging.log4j/groupIdartifactIdlog4j-core/artifactIdversion2.19.0/version/dependencydependencygroupIdorg.apache.logging.log4j/groupIdartifactIdlog4j-slf4j2-impl/artifactIdversion2.19.0/version/dependency /dependencies②准备被代理的目标资源 接口 public interface Calculator {int add(int i, int j);int sub(int i, int j);int mul(int i, int j);int div(int i, int j);}实现类 Component public class CalculatorImpl implements Calculator {Overridepublic int add(int i, int j) {int result i j;System.out.println(方法内部 result result);return result;}Overridepublic int sub(int i, int j) {int result i - j;System.out.println(方法内部 result result);return result;}Overridepublic int mul(int i, int j) {int result i * j;System.out.println(方法内部 result result);return result;}Overridepublic int div(int i, int j) {int result i / j;System.out.println(方法内部 result result);return result;} }3、创建切面类并配置 // Aspect表示这个类是一个切面类 Aspect // Component注解保证这个切面类能够放入IOC容器 Component public class LogAspect {Before(execution(public int com.atguigu.aop.annotation.CalculatorImpl.*(..)))public void beforeMethod(JoinPoint joinPoint){String methodName joinPoint.getSignature().getName();String args Arrays.toString(joinPoint.getArgs());System.out.println(Logger--前置通知方法名methodName参数args);}After(execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..)))public void afterMethod(JoinPoint joinPoint){String methodName joinPoint.getSignature().getName();System.out.println(Logger--后置通知方法名methodName);}AfterReturning(value execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..)), returning result)public void afterReturningMethod(JoinPoint joinPoint, Object result){String methodName joinPoint.getSignature().getName();System.out.println(Logger--返回通知方法名methodName结果result);}AfterThrowing(value execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..)), throwing ex)public void afterThrowingMethod(JoinPoint joinPoint, Throwable ex){String methodName joinPoint.getSignature().getName();System.out.println(Logger--异常通知方法名methodName异常ex);}Around(execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..)))public Object aroundMethod(ProceedingJoinPoint joinPoint){String methodName joinPoint.getSignature().getName();String args Arrays.toString(joinPoint.getArgs());Object result null;try {System.out.println(环绕通知--目标对象方法执行之前);//目标对象连接点方法的执行result joinPoint.proceed();System.out.println(环绕通知--目标对象方法返回值之后);} catch (Throwable throwable) {throwable.printStackTrace();System.out.println(环绕通知--目标对象方法出现异常时);} finally {System.out.println(环绕通知--目标对象方法执行完毕);}return result;}}在Spring的配置文件中配置 ?xml version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:contexthttp://www.springframework.org/schema/contextxmlns:aophttp://www.springframework.org/schema/aopxsi:schemaLocationhttp://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd!--基于注解的AOP的实现1、将目标对象和切面交给IOC容器管理注解扫描2、开启AspectJ的自动代理为目标对象自动生成代理3、将切面类通过注解Aspect标识--context:component-scan base-packagecom.atguigu.aop.annotation/context:component-scanaop:aspectj-autoproxy / /beans执行测试 public class CalculatorTest {private Logger logger LoggerFactory.getLogger(CalculatorTest.class);Testpublic void testAdd(){ApplicationContext ac new ClassPathXmlApplicationContext(beans.xml);Calculator calculator ac.getBean( Calculator.class);int add calculator.add(1, 1);logger.info(执行成功:add);}}4、各种通知 前置通知使用Before注解标识在被代理的目标方法前执行返回通知使用AfterReturning注解标识在被代理的目标方法成功结束后执行寿终正寝异常通知使用AfterThrowing注解标识在被代理的目标方法异常结束后执行死于非命后置通知使用After注解标识在被代理的目标方法最终结束后执行盖棺定论环绕通知使用Around注解标识使用try…catch…finally结构围绕整个被代理的目标方法包括上面四种通知对应的所有位置 各种通知的执行顺序 Spring版本5.3.x以前 前置通知目标操作后置通知返回通知或异常通知 Spring版本5.3.x以后 前置通知目标操作返回通知或异常通知后置通知 5、切入点表达式语法 ①作用 ②语法细节 用*号代替“权限修饰符”和“返回值”部分表示“权限修饰符”和“返回值”不限 在包名的部分一个“*”号只能代表包的层次结构中的一层表示这一层是任意的。 例如*.Hello匹配com.Hello不匹配com.atguigu.Hello 在包名的部分使用“*…”表示包名任意、包的层次深度任意 在类名的部分类名部分整体用*号代替表示类名任意 在类名的部分可以使用*号代替类名的一部分 例如*Service匹配所有名称以Service结尾的类或接口 在方法名部分可以使用*号表示方法名任意 在方法名部分可以使用*号代替方法名的一部分 例如*Operation匹配所有方法名以Operation结尾的方法 在方法参数列表部分使用(…)表示参数列表任意 在方法参数列表部分使用(int,…)表示参数列表以一个int类型的参数开头 在方法参数列表部分基本数据类型和对应的包装类型是不一样的 切入点表达式中使用 int 和实际方法中 Integer 是不匹配的 在方法返回值部分如果想要明确指定一个返回值类型那么必须同时写明权限修饰符 例如execution(public int …Service.(…, int)) 正确 例如execution( int *…Service.(…, int)) 错误 6、重用切入点表达式 ①声明 Pointcut(execution(* com.atguigu.aop.annotation.*.*(..))) public void pointCut(){}②在同一个切面中使用 Before(pointCut()) public void beforeMethod(JoinPoint joinPoint){String methodName joinPoint.getSignature().getName();String args Arrays.toString(joinPoint.getArgs());System.out.println(Logger--前置通知方法名methodName参数args); }③在不同切面中使用 Before(com.atguigu.aop.CommonPointCut.pointCut()) public void beforeMethod(JoinPoint joinPoint){String methodName joinPoint.getSignature().getName();String args Arrays.toString(joinPoint.getArgs());System.out.println(Logger--前置通知方法名methodName参数args); }7、获取通知的相关信息 ①获取连接点信息 获取连接点信息可以在通知方法的参数位置设置JoinPoint类型的形参 Before(execution(public int com.atguigu.aop.annotation.CalculatorImpl.*(..))) public void beforeMethod(JoinPoint joinPoint){//获取连接点的签名信息String methodName joinPoint.getSignature().getName();//获取目标方法到的实参信息String args Arrays.toString(joinPoint.getArgs());System.out.println(Logger--前置通知方法名methodName参数args); }②获取目标方法的返回值 AfterReturning中的属性returning用来将通知方法的某个形参接收目标方法的返回值 AfterReturning(value execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..)), returning result) public void afterReturningMethod(JoinPoint joinPoint, Object result){String methodName joinPoint.getSignature().getName();System.out.println(Logger--返回通知方法名methodName结果result); }③获取目标方法的异常 AfterThrowing中的属性throwing用来将通知方法的某个形参接收目标方法的异常 AfterThrowing(value execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..)), throwing ex) public void afterThrowingMethod(JoinPoint joinPoint, Throwable ex){String methodName joinPoint.getSignature().getName();System.out.println(Logger--异常通知方法名methodName异常ex); }8、环绕通知 Around(execution(* com.atguigu.aop.annotation.CalculatorImpl.*(..))) public Object aroundMethod(ProceedingJoinPoint joinPoint){String methodName joinPoint.getSignature().getName();String args Arrays.toString(joinPoint.getArgs());Object result null;try {System.out.println(环绕通知--目标对象方法执行之前);//目标方法的执行目标方法的返回值一定要返回给外界调用者result joinPoint.proceed();System.out.println(环绕通知--目标对象方法返回值之后);} catch (Throwable throwable) {throwable.printStackTrace();System.out.println(环绕通知--目标对象方法出现异常时);} finally {System.out.println(环绕通知--目标对象方法执行完毕);}return result; }9、切面的优先级 相同目标方法上同时存在多个切面时切面的优先级控制切面的内外嵌套顺序。 优先级高的切面外面优先级低的切面里面 使用Order注解可以控制切面的优先级 Order(较小的数)优先级高Order(较大的数)优先级低 二、基于XML的AOP 1、准备工作 参考基于注解的AOP环境 2、实现 context:component-scan base-packagecom.atguigu.aop.xml/context:component-scanaop:config!--配置切面类--aop:aspect refloggerAspectaop:pointcut idpointCut expressionexecution(* com.atguigu.aop.xml.CalculatorImpl.*(..))/aop:before methodbeforeMethod pointcut-refpointCut/aop:beforeaop:after methodafterMethod pointcut-refpointCut/aop:afteraop:after-returning methodafterReturningMethod returningresult pointcut-refpointCut/aop:after-returningaop:after-throwing methodafterThrowingMethod throwingex pointcut-refpointCut/aop:after-throwingaop:around methodaroundMethod pointcut-refpointCut/aop:around/aop:aspect /aop:config总结 以上就是spring之面向切面AOP2的相关知识点希望对你有所帮助。 积跬步以至千里积怠惰以至深渊。时代在这跟着你一起努力哦
http://www.dnsts.com.cn/news/179781.html

相关文章:

  • 泉港做网站公司商城app开发费用多少
  • 宁波网络推广产品服务seo是干什么的
  • 南京网站维护html5开发工具有哪些
  • 自己的网站建设合肥 做网站的公司
  • vs2012网站开发环境it运维工资
  • 备份整个网站洗头竖鞋带名片改良授权做网站不贵
  • 企业网站货物查询怎么做WordPress中文seo
  • 企业网站建设价格上传wordpress到服务器
  • 襄阳做网站公司有哪些搜索引擎推广的特点
  • wordpress $数组网站内容seo
  • 搭建网站php源码简述网站开发工作流程
  • 网站备案完才能建站吗2024最新版qq官方下载
  • 做视频比较好的理财网站有哪些wordpress分页重写
  • 钟表商城网站建设方案做网站怎么不被找到
  • 我想做个卷帘门网站怎么做网站构成的作用是什么
  • 免备案服务器推荐seo优化顾问服务阿亮
  • 化州 网站建设厦门网站设计公司找哪家福建小程序开发
  • 交通运输行业网站建设cetos做网站
  • 上海市住房和城乡建设厅网站查询广告公司业务推广
  • 企业做网站价格软件设计和软件开发的区别
  • 自己做的影视会员网站违法么wordpress 增加域名
  • 建设 公司 网站 请示网站备案产品信息错误
  • 家居行业网站开发个人网站主页设计
  • 厦门网站建设方案报价上海浦东医院网站建设
  • frontpage建设网站的图片视频号分销解决方案的特点
  • 不花钱网站怎么做cad效果图怎么制作
  • 中文企业网站模板htmlwordpress json api auth
  • 做药物研发的人上什么网站兰州网站建设营销q479185700刷屏
  • 免费凡科网站会员卡系统一般哪里买
  • 做微信公众号网站源码上海开发小程序