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

百度网站怎么提升排名深圳十大品牌策划公司

百度网站怎么提升排名,深圳十大品牌策划公司,wordpress 哪些插件,cms网站01.AOP技术是对于面向对象编程#xff08;OOP#xff09;的补充。是按照OCP原则进行的编写#xff0c;(ocp是修改模块权限不行#xff0c;扩充可以) 02.写一个例子#xff1a; 创建一个新的java项目#xff0c;在main主启动类中#xff0c;写如下代码。 package com.co…01.AOP技术是对于面向对象编程OOP的补充。是按照OCP原则进行的编写(ocp是修改模块权限不行扩充可以) 02.写一个例子 创建一个新的java项目在main主启动类中写如下代码。 package com.company;interface mainService{void send(); } class DefaultServiceImpl implements mainService {Overridepublic void send() {System.out.println(hello);} } public class main {public static void main(String[] args){DefaultServiceImpl defaultServicenew DefaultServiceImpl();defaultService.send();} } 一个接口一个接口实现类一个main主方法。 03.如果要实现显示接口实现类中的send方法运行的时间一般的就在实现类中的send方法前后添加system.currenttimeMills Overridepublic void send() {System.out.println(start:System.currentTimeMillis());System.out.println(hello);System.out.println(end:System.currentTimeMillis());}04.如果在项目的发布后或者以后接口实现类以后代码多如何去修改项目呢实现显示运行时间呢 方法一继续写一个子类去继承接口实现类。 class DefaultServiceImpl implements mainService {Overridepublic void send() {// System.out.println(start:System.currentTimeMillis());System.out.println(hello);// System.out.println(end:System.currentTimeMillis());} }class logDefaultImpl extends DefaultServiceImpl {Overridepublic void send() {System.out.println(start:System.currentTimeMillis());System.out.println(hello);System.out.println(end:System.currentTimeMillis());} }package com.company;interface mainService{void send(); } class DefaultServiceImpl implements mainService {Overridepublic void send() {// System.out.println(start:System.currentTimeMillis());System.out.println(hello);// System.out.println(end:System.currentTimeMillis());} }class logDefaultImpl extends DefaultServiceImpl {Overridepublic void send() {System.out.println(start:System.currentTimeMillis());System.out.println(hello);System.out.println(end:System.currentTimeMillis());} } public class main {public static void main(String[] args){mainService logDefaultImplnew logDefaultImpl();logDefaultImpl.send();} } 方法二如果接口实现类被final修饰的话不能用子类来继承可以写一个集合来实现运行时间的功能 final class DefaultServiceImpl implements mainService {Overridepublic void send() {System.out.println(hello);} } 创建一个新的类也同样实现接口mainService 在这个类中声明一个接口的变量 class logDefaultImpl implements mainService {private mainService mainservice;public logDefaultImpl(mainService mainservice){this.mainservicemainservice;}Overridepublic void send() {System.out.println(start:System.currentTimeMillis());mainservice.send();System.out.println(end:System.currentTimeMillis());} }在main主方法中 public class main {public static void main(String[] args){mainService DefaultServiceImplnew DefaultServiceImpl();DefaultServiceImpl.send();mainService lognew logDefaultImpl(new DefaultServiceImpl());log.send();} }通过构造函数将final修饰的接口实现类传入到新的类中结合方法来实现显示运行时间的功能。 05.AOP技术的底层实现。 AOP对象是通过代理对象来实现的代理对象有两种一种是通过JDK来实现的一种是通过CGlib来实现的。 jdk的代理就好像是使用一个新的类去继承接口再来包含目标接口实现类 cglib是写一个子类去继承目标接口实现类。 06.AOP的术语 1切面就是写了相关扩展功能的类 2.通知就是切面中的相关方法 3.连接点就是需要扩展的方法 4.切入点就是连接点所在的类有的时候也可能是一整个包。 07.在springboot中去实现AOP技术 先在maven项目中导入相关的依赖。 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactId /dependency在去写切面类这里需要用注解Aspect标识这个类是切面类用Component来将类交给spring容器进行管理。还需要使用到log4j来进行日志管理Slf4j。 package com.cy.common;import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Pointcut; import org.springframework.stereotype.Component; Slf4j//日志 Aspect//标识切面类 Component//交给spring容器管理 public class sysLogAspect {Pointcut(bean(sysUserServiceImpl))//Pointcut标识连接点多个切入点的集合public void logPointCut(){} Around(logPointCut())//这个是环绕通知属性是切入点public Object around(ProceedingJoinPoint joinPoint) throws Throwable {//还是计算运行时间//并且执行方法Long startTimeSystem.currentTimeMillis();Object object joinPoint.proceed();//调用本切面的其他方法或者其他切面的通知和目标Long endTimeSystem.currentTimeMillis();log.info(总时长是,endTime-startTime);return object;}} Pointcut标识连接点多个切入点的集合这里用来写的是连接点bean标识spring容器中的类括号中的是类名一般是接口的实现类impl。 这个切面的意义在于sysUserServiceImpl这个接口实现类的每一个方法都扩展了功能记录运行时间。 07.在springboot项目导入AOP依赖后项目实现路径发送了改变。 springboot版本2.x后默认AOP代理是Cglib 运行 AOP通知有五种 package com.cy.common;import lombok.extern.slf4j.Slf4j; import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.*; import org.springframework.stereotype.Component;Slf4j Aspect Component public class sysTimeAspect {Pointcut(bean(sysUserServiceImpl))public void doTime(){}Around(doTime())public Object aroud(ProceedingJoinPoint joinPoint) throws Throwable {Long startTimeSystem.currentTimeMillis();Object object joinPoint.proceed();Long endTimeSystem.currentTimeMillis();log.info(总时长是,endTime-startTime);System.out.println(通知around);return object;}//前置Before(doTime())public void before() {System.out.println(通知before);}//后置After(doTime())public void after() {System.out.println(通知before);}//正常AfterReturning(doTime())public void AfterReturn() {System.out.println(通知AfterReturning);}//异常AfterThrowing(doTime())public void AfterThrow() {System.out.println(通知AfterThrowing);} } 使用通知AfterThrowing在切面中去写一个异常通知就是目标接口类方法运行时候有异常切面类处理。 Slf4j Aspect Component public class sysExceptionAspect {AfterThrowing(pointcut bean(sysUserServiceImpl),throwing e)//pointcut是连接点throwing是抛出的异常public void doHandlerException(JoinPoint jp//这个是切入点,Throwable e){MethodSignature ms (MethodSignature)jp.getSignature();log.error({},exception msg is {},ms.getName(),e.getMessage());}}getsignature返回的类型是signature。 如果想要所有的接口实现类的运行方法报错时候有这个切面的类的AfterThrowing来处理异常可以在bean中去写bean*ServiceImpl
http://www.w-s-a.com/news/988770/

相关文章:

  • 玉雕网站建设八点品牌设计公司招聘
  • 服务器可以自己的网站吗flash 网站 源码
  • 湖南做网站 搜搜磐石网络网站注册收入
  • 北京软件网站开发装修设计培训机构
  • 哪个网站能帮助做路书网站建设的技巧
  • 上海网站备案在哪里在国外怎么做网站
  • 做网站得花多钱乡村振兴网站建设
  • 站设计培训课程wordpress自动回复
  • 上海闵行区 网站建设永久免费crm软件下载
  • 天津营销网站建设公司排名台州网站排名公司
  • 环保网站 怎么做物流网站的功能与特色
  • 网站多久才会被收录服务器租用泰海
  • 电商网站建设合同模板临汾推广型网站建设
  • 天猫商务网站建设目的长春网站设计
  • 公司网站建设会议纪要昆山高端网站建设机构
  • 做消费网站流程深圳网站设计价格
  • 做电影网站怎么接广告中国最新军事新闻视频
  • 网站推广设计做哪些设置自动删除的wordpress
  • 东莞东坑网站设计专业网站制作设
  • 网站怎么做现场直播视频成都科技网站建设找
  • 个人网页设计步骤网站没有内容 能做优化吗
  • 专业网站建设公司招聘网站排行榜
  • 网站建设规范方法企业解决方案架构
  • ae做网站导航wordpress门户
  • 重庆市网站备案材料云南做网站
  • 网页设计模板网站免费珠海视窗网
  • 茂名模板建站定制WordPress注册不提示
  • 陕西营销型手机网站建设深圳制作网站服务
  • 受欢迎的锦州网站建设Wordpress 图片左右滑动
  • 湖南优化网站建设线上网站建设需求