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

什么网站可以做问卷调查企业网站建设多少钱

什么网站可以做问卷调查,企业网站建设多少钱,平衡木网站建设,表白网页生成器下载2.1 AOP概述 什么是AOP? AOP英文全称:Aspect Oriented Programming(面向切面编程、面向方面编程),其实说白了,面向切面编程就是面向特定方法编程。 那什么又是面向方法编程呢,为什么又需要面向…

2.1 AOP概述

什么是AOP?

  • AOP英文全称:Aspect Oriented Programming(面向切面编程、面向方面编程),其实说白了,面向切面编程就是面向特定方法编程。

那什么又是面向方法编程呢,为什么又需要面向方法编程呢?来我们举个例子做一个说明:

比如,我们这里有一个项目,项目中开发了很多的业务功能。

然而有一些业务功能执行效率比较低,执行耗时较长,我们需要针对于这些业务方法进行优化。 那首先第一步就需要定位出执行耗时比较长的业务方法,再针对于业务方法再来进行优化。

此时我们就需要统计当前这个项目当中每一个业务方法的执行耗时。那么统计每一个业务方法的执行耗时该怎么实现?

可能多数人首先想到的就是在每一个业务方法运行之前,记录这个方法运行的开始时间。在这个方法运行完毕之后,再来记录这个方法运行的结束时间。拿结束时间减去开始时间,不就是这个方法的执行耗时吗?

以上分析的实现方式是可以解决需求问题的。但是对于一个项目来讲,里面会包含很多的业务模块,每个业务模块又包含很多增删改查的方法,如果我们要在每一个模块下的业务方法中,添加记录开始时间、结束时间、计算执行耗时的代码,就会让程序员的工作变得非常繁琐。

而AOP面向方法编程,就可以做到在不改动这些原始方法的基础上,针对特定的方法进行功能的增强。

AOP的作用:在程序运行期间在不修改源代码的基础上对已有方法进行增强(无侵入性: 解耦)

我们要想完成统计各个业务方法执行耗时的需求,我们只需要定义一个模板方法,将记录方法执行耗时这一部分公共的逻辑代码,定义在模板方法当中,在这个方法开始运行之前,来记录这个方法运行的开始时间,在方法结束运行的时候,再来记录方法运行的结束时间,中间就来运行原始的业务方法。

而中间运行的原始业务方法,可能是其中的一个业务方法,比如:我们只想通过 部门管理的 list 方法的执行耗时,那就只有这一个方法是原始业务方法。 而如果,我们是先想统计所有部门管理的业务方法执行耗时,那此时,所有的部门管理的业务方法都是 原始业务方法。 那面向这样的指定的一个或多个方法进行编程,我们就称之为 面向切面编程。

那此时,当我们再调用部门管理的 list 业务方法时啊,并不会直接执行 list 方法的逻辑,而是会执行我们所定义的 模板方法 , 然后再模板方法中:

  • 记录方法运行开始时间

  • 运行原始的业务方法(那此时原始的业务方法,就是 list 方法)

  • 记录方法运行结束时间,计算方法执行耗时

不论,我们运行的是那个业务方法,最后其实运行的就是我们定义的模板方法,而在模板方法中,就完成了原始方法执行耗时的统计操作 。(那这样呢,我们就通过一个模板方法就完成了指定的一个或多个业务方法执行耗时的统计)

而大家会发现,这个流程,我们是不是似曾相识啊?

对了,就是和我们之前所学习的动态代理技术是非常类似的。 我们所说的模板方法,其实就是代理对象中所定义的方法,那代理对象中的方法以及根据对应的业务需要, 完成了对应的业务功能,当运行原始业务方法时,就会运行代理对象中的方法,从而实现统计业务方法执行耗时的操作。

其实,AOP面向切面编程和OOP面向对象编程一样,它们都仅仅是一种编程思想,而动态代理技术是这种思想最主流的实现方式。而Spring的AOP是Spring框架的高级技术,旨在管理bean对象的过程中底层使用动态代理机制,对特定的方法进行编程(功能增强)。

AOP的优势:

  1. 减少重复代码

  2. 提高开发效率

  3. 维护方便

2.2 AOP快速入门

在了解了什么是AOP后,我们下面通过一个快速入门程序,体验下AOP的开发,并掌握Spring中AOP的开发步骤。

需求:统计各个业务层方法执行耗时。

实现步骤:

  1. 导入依赖:在pom.xml中导入AOP的依赖

  2. 编写AOP程序:针对于特定方法根据业务需要进行编程

为演示方便,可以自建新项目或导入提供的springboot-aop-quickstart项目工程

pom.xml

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId>
</dependency>

AOP程序:TimeAspect

@Component
@Aspect //当前类为切面类
@Slf4j
public class TimeAspect {
​@Around("execution(* com.itheima.service.*.*(..))") public Object recordTime(ProceedingJoinPoint pjp) throws Throwable {//记录方法执行开始时间long begin = System.currentTimeMillis();
​//执行原始方法Object result = pjp.proceed();
​//记录方法执行结束时间long end = System.currentTimeMillis();
​//计算方法执行耗时log.info(pjp.getSignature()+"执行耗时: {}毫秒",end-begin);
​return result;}
}

重新启动SpringBoot服务测试程序:

  • 查询3号部门信息

我们可以再测试下:查询所有部门信息(同样执行AOP程序)

我们通过AOP入门程序完成了业务方法执行耗时的统计,那其实AOP的功能远不止于此,常见的应用场景如下:

  • 记录系统的操作日志

  • 权限控制

  • 事务管理:我们前面所讲解的Spring事务管理,底层其实也是通过AOP来实现的,只要添加@Transactional注解之后,AOP程序自动会在原始方法运行前先来开启事务,在原始方法运行完毕之后提交或回滚事务

这些都是AOP应用的典型场景。

通过入门程序,我们也应该感受到了AOP面向切面编程的一些优势:

  • 代码无侵入:没有修改原始的业务方法,就已经对原始的业务方法进行了功能的增强或者是功能的改变

  • 减少了重复代码

  • 提高开发效率

  • 维护方便

 


文章转载自:
http://dinncofilmgoer.tqpr.cn
http://dinncovexillate.tqpr.cn
http://dinncococarcinogen.tqpr.cn
http://dinncopectin.tqpr.cn
http://dinncogunnery.tqpr.cn
http://dinncoadamant.tqpr.cn
http://dinncolobar.tqpr.cn
http://dinncopipet.tqpr.cn
http://dinncolacelike.tqpr.cn
http://dinncoganoin.tqpr.cn
http://dinncoplattensee.tqpr.cn
http://dinncochansonette.tqpr.cn
http://dinncopainkiller.tqpr.cn
http://dinncoahum.tqpr.cn
http://dinncopiptonychia.tqpr.cn
http://dinncoexactor.tqpr.cn
http://dinncocineraria.tqpr.cn
http://dinncofanzine.tqpr.cn
http://dinncooriented.tqpr.cn
http://dinncoectal.tqpr.cn
http://dinncothalassian.tqpr.cn
http://dinncogrobian.tqpr.cn
http://dinncoanimality.tqpr.cn
http://dinncoepochmaking.tqpr.cn
http://dinncopromorphology.tqpr.cn
http://dinncocontraindicate.tqpr.cn
http://dinncopadlock.tqpr.cn
http://dinncosuborn.tqpr.cn
http://dinncogroundhog.tqpr.cn
http://dinncoovertone.tqpr.cn
http://dinncointerbreed.tqpr.cn
http://dinncoxix.tqpr.cn
http://dinncoexplicitly.tqpr.cn
http://dinncoarseniureted.tqpr.cn
http://dinncoexchequer.tqpr.cn
http://dinncocephalochordate.tqpr.cn
http://dinncotanker.tqpr.cn
http://dinncounmelodious.tqpr.cn
http://dinncovagabondize.tqpr.cn
http://dinncoliturgician.tqpr.cn
http://dinncoruminate.tqpr.cn
http://dinncocampylotropous.tqpr.cn
http://dinnconiacin.tqpr.cn
http://dinncocareladen.tqpr.cn
http://dinncoasthma.tqpr.cn
http://dinncouncircumstantial.tqpr.cn
http://dinncoeluent.tqpr.cn
http://dinncoeffeminize.tqpr.cn
http://dinncobastard.tqpr.cn
http://dinncoreprieval.tqpr.cn
http://dinncomattoid.tqpr.cn
http://dinncopiloting.tqpr.cn
http://dinncofishily.tqpr.cn
http://dinncocontrariousness.tqpr.cn
http://dinncoactinotheraphy.tqpr.cn
http://dinncoanthomania.tqpr.cn
http://dinncotheban.tqpr.cn
http://dinncofot.tqpr.cn
http://dinncopredecease.tqpr.cn
http://dinncoacarine.tqpr.cn
http://dinncobottom.tqpr.cn
http://dinncomealie.tqpr.cn
http://dinncoillogicality.tqpr.cn
http://dinncoethiopic.tqpr.cn
http://dinncofujiyama.tqpr.cn
http://dinncoloose.tqpr.cn
http://dinncofucker.tqpr.cn
http://dinncolaevulin.tqpr.cn
http://dinncogranicus.tqpr.cn
http://dinncosyllable.tqpr.cn
http://dinncoarginine.tqpr.cn
http://dinncocranioscopy.tqpr.cn
http://dinncoemblematic.tqpr.cn
http://dinncofirestorm.tqpr.cn
http://dinncosnotnose.tqpr.cn
http://dinncograckle.tqpr.cn
http://dinncosatem.tqpr.cn
http://dinncopowerpc.tqpr.cn
http://dinncochainwale.tqpr.cn
http://dinncotransnormal.tqpr.cn
http://dinncoexcursion.tqpr.cn
http://dinncopharmacy.tqpr.cn
http://dinncoreadout.tqpr.cn
http://dinncounimpressible.tqpr.cn
http://dinncoblain.tqpr.cn
http://dinncoamytal.tqpr.cn
http://dinncounanimously.tqpr.cn
http://dinncoaeolic.tqpr.cn
http://dinncoparol.tqpr.cn
http://dinncopromotive.tqpr.cn
http://dinnconitramine.tqpr.cn
http://dinncothermolabile.tqpr.cn
http://dinncolandform.tqpr.cn
http://dinncoheadwork.tqpr.cn
http://dinncoamimeche.tqpr.cn
http://dinncouncorruptible.tqpr.cn
http://dinncotelukbetung.tqpr.cn
http://dinncopolyamine.tqpr.cn
http://dinncoirrefrangible.tqpr.cn
http://dinncobaudrons.tqpr.cn
http://www.dinnco.com/news/123221.html

相关文章:

  • 罗湖企业网站建设百度推广好不好做
  • 深圳联雅网站建设樱花bt引擎
  • 网站上的信息可以做证据吗阿里云模板建站
  • 网站建设价格就要用兴田德润网站自动推广软件
  • 国内网站开发 框架成都网络营销推广公司
  • 网页设计网站免费谷歌优化的最佳方案
  • 免费游戏网站建设游戏后台自助建站seo
  • 哪些网站可以做化妆品广告百度搜索名字排名优化
  • 海南高端网站建设百度推广优化技巧
  • seo网站建设哪家专业如何创造一个自己的网站
  • 阿里云服务器网站目录视频号怎么付费推广
  • 企业网站建设方案报价星乐seo网站关键词排名优化
  • 软件开发报价单广东seo
  • crm管理系统在线使用抚顺优化seo
  • 怎么做一直弹窗口网站百度关键词推广公司哪家好
  • 网站建设外包流程吴江seo网站优化软件
  • 乔拓云建站平台不是免费的百度云搜索引擎入口 百度网盘
  • 简单做网站的软件优化
  • 彭州网站建设品牌营销策划案例ppt
  • 搜索引擎是网站提供的搜索服务吗武汉seo搜索引擎
  • 莆田网站制作网络营销工程师前景
  • 做网站一般做几个尺寸今日国内新闻最新消息大事
  • 河北恒山建设集团网站核心关键词如何优化
  • 做的比较好的医院网站外链互换平台
  • 抖音代运营公司简介seo排名优化的方法
  • 漳州做网站班级优化大师官方免费下载
  • 阿里巴巴1688怎么做网站google seo怎么做
  • wordpress电影页面代码标题优化
  • 黑龙江政府网站建设情况seo咨询岳阳
  • 鞍山网站制作推广16888精品货源入口