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

设计公司网站怎么做网站快速排名服务

设计公司网站怎么做,网站快速排名服务,哈尔滨商城网站建设,漳州网站建设哪家最权威概念 这里需要提前了解什么是Spring的AOP(Aspect Oriented Programming)。是在OOP(面向对象)思想的一种拓展思想。简单来说就是将某个代码块嵌入到其它的代码块中。笔者先前学Spring也有学什么IoC啊AOP啊,但实际上没有…

概念

        这里需要提前了解什么是Spring的AOP(Aspect Oriented Programming)。是在OOP(面向对象)思想的一种拓展思想。简单来说就是将某个代码块嵌入到其它的代码块中。笔者先前学Spring也有学什么IoC啊AOP啊,但实际上没有用过、就那听过学过没啥用的。。没会儿就忘记了。那种也就是个了解,好像知道是个什么事儿?当时还特地去背关于AOP的那几个专有名词?现在想想有点好笑。

        不过还是需要提前巩固知道几个词。看完了下面的这三个词的用法就开始进入模拟实战。

切面(Aspect):由切点和通知组成。即使用@Aspect注解的类

切点(Pointcut):可以限定访问修饰符、类全限定名、方法名和参数类型,甚至用于匹配注解

通知(Advice):想要嵌入到其它代码块的代码块。其中包括五种类型。

        @Before(目标方法执行前执行)

        @After(目标方法执行后执行)

        @AfterReturning(目标方法返回结果后不出现异常才执行)

        @AfterThrowin(出现异常才执行)

        @Around(以上都包括)

引入依赖

<!-- Spring Boot -->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency><!-- 简化开发 -->
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional>
</dependency><!-- AOP -->
<dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId>
</dependency>

创建注解

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
public @interface Log {/*** 描述** @return {String}*/String value();}

业务代码

@Slf4j
@RestController
@RequestMapping("/log")
public class LogController {@Log("AOP测试")@GetMapping("/aspect")public void aspect() {log.info("进入AOP测试方法");for(int i = 0; i < 10; ++i) {log.info("执行业务逻辑{}", i);}log.info("结束AOP测试方法");}}

编写切面

有切点

@Slf4j
@Component
@Aspect
public class LogAspect {@Autowiredprivate ApplicationEventPublisher publisher;/*** 切点* 这里面主要掌握两个东西:*  1、如果使用注解的话就需要获取注解的类全限定名*  2、执行的execution表达式(这是比较重要掌握的) 这里面有四个参数 需要知道的是*也可以表示前缀或者后缀 和SQL中的"%"类似*      一、方法的访问权限修饰符(public/protected/default/private)*      二、方法的返回值类型*      三、类的全限定名(包名.类名)*      四、*(..)的第一个表示方法名;括号内表示参数,而两个点表示接收任何参数类型*/@Pointcut("@annotation(com.chf.annotation.Log) && execution(public * com.chf.controller.*Controller.*(..))")public void logPointcut() {}@SneakyThrows@Around("logPointcut()")public Object around(ProceedingJoinPoint point) {// 获取注解完后解析其内部的属性MethodSignature signature = (MethodSignature) point.getSignature();log.info("获取注解,{}", signature); // void com.chf.controller.LogController.aspect()Method method = signature.getMethod();log.info("获取注解的方法,{}", method);// public void com.chf.controller.LogController.aspect()Log logAnnotation = method.getAnnotation(Log.class);log.info("获取使用注解的value参数,{}", logAnnotation.value()); // AOP测试// 发送异步事件Long startTime = System.currentTimeMillis();Object o;try {o = point.proceed();} finally {// 这里可以使用发布订阅模式发布异步事件 至于使用哪一种发布订阅模式就看业务场景了Long endTime = System.currentTimeMillis();publisher.publishEvent(new LogEvent("事件处理的时间是:" + (endTime - startTime) + "ms"));}return o;}
}

无切点

@Slf4j
@Component
@Aspect
public class LogAspect {@Autowiredprivate ApplicationEventPublisher publisher;@SneakyThrows@Around("@annotation(logAnnotation) && execution(public * com.chf.controller.*Controller.*(..))")public Object around(ProceedingJoinPoint point, Log logAnnotation) {// 获取注解完后解析其内部的属性MethodSignature signature = (MethodSignature) point.getSignature();log.info("获取注解,{}", signature); // void com.chf.controller.LogController.aspect()Method method = signature.getMethod();log.info("获取注解的方法,{}", method);// public void com.chf.controller.LogController.aspect()Log logAnnotation = method.getAnnotation(Log.class);log.info("获取使用注解的value参数,{}", logAnnotation.value()); // AOP测试// 发送异步事件Long startTime = System.currentTimeMillis();Object o;try {o = point.proceed();} finally {Long endTime = System.currentTimeMillis();publisher.publishEvent(new LogEvent("事件处理的时间是:" + (endTime - startTime) + "ms"));}return o;}
}

测试

        不了解Spring的发布订阅模式可以看这篇博文:https://blog.csdn.net/m0_65563175/article/details/131899828?spm=1001.2014.3001.5501


文章转载自:
http://dinncooverlie.ydfr.cn
http://dinncooft.ydfr.cn
http://dinncospiritualistic.ydfr.cn
http://dinncoantivenom.ydfr.cn
http://dinncojohanna.ydfr.cn
http://dinncoacnemia.ydfr.cn
http://dinncosore.ydfr.cn
http://dinncoastrophotometry.ydfr.cn
http://dinncorowover.ydfr.cn
http://dinncorehabilitation.ydfr.cn
http://dinncobywalk.ydfr.cn
http://dinncokat.ydfr.cn
http://dinncoerythorbic.ydfr.cn
http://dinncolinger.ydfr.cn
http://dinncocapias.ydfr.cn
http://dinncodubitant.ydfr.cn
http://dinncolampstandard.ydfr.cn
http://dinncoavowry.ydfr.cn
http://dinncohour.ydfr.cn
http://dinncostreetlamp.ydfr.cn
http://dinncoroan.ydfr.cn
http://dinncoexemplar.ydfr.cn
http://dinncopsalmodic.ydfr.cn
http://dinncoslighting.ydfr.cn
http://dinncoincentre.ydfr.cn
http://dinncoautotimer.ydfr.cn
http://dinncosentimentalise.ydfr.cn
http://dinncocraven.ydfr.cn
http://dinncoblame.ydfr.cn
http://dinncoerythrochroism.ydfr.cn
http://dinncodovelet.ydfr.cn
http://dinncoprudent.ydfr.cn
http://dinncopejorate.ydfr.cn
http://dinncoincontestably.ydfr.cn
http://dinncochimurenga.ydfr.cn
http://dinncoappel.ydfr.cn
http://dinncodurzi.ydfr.cn
http://dinncobrassy.ydfr.cn
http://dinncounstockinged.ydfr.cn
http://dinncostenciller.ydfr.cn
http://dinncocrackleware.ydfr.cn
http://dinncomanicotti.ydfr.cn
http://dinncoperuse.ydfr.cn
http://dinncosorely.ydfr.cn
http://dinncotoolhouse.ydfr.cn
http://dinncophilologian.ydfr.cn
http://dinncopoofy.ydfr.cn
http://dinncofricative.ydfr.cn
http://dinncoturtleback.ydfr.cn
http://dinncoonomastics.ydfr.cn
http://dinncopicture.ydfr.cn
http://dinncohysterical.ydfr.cn
http://dinncodeckhead.ydfr.cn
http://dinncorifampicin.ydfr.cn
http://dinncofrimaire.ydfr.cn
http://dinncoier.ydfr.cn
http://dinncodecompresssion.ydfr.cn
http://dinncooligopoly.ydfr.cn
http://dinncomammilliform.ydfr.cn
http://dinncobevel.ydfr.cn
http://dinncominimize.ydfr.cn
http://dinncosolvable.ydfr.cn
http://dinncoparaldehyde.ydfr.cn
http://dinncobipolar.ydfr.cn
http://dinncosciurid.ydfr.cn
http://dinncomouthy.ydfr.cn
http://dinnconic.ydfr.cn
http://dinncology.ydfr.cn
http://dinncoleal.ydfr.cn
http://dinncopalatine.ydfr.cn
http://dinncokirgizia.ydfr.cn
http://dinncoprecool.ydfr.cn
http://dinncodouai.ydfr.cn
http://dinncocalyces.ydfr.cn
http://dinncohomoscedastic.ydfr.cn
http://dinncochlordane.ydfr.cn
http://dinncoisolating.ydfr.cn
http://dinncorobotry.ydfr.cn
http://dinncodulcet.ydfr.cn
http://dinncolange.ydfr.cn
http://dinncocookie.ydfr.cn
http://dinncotenpenny.ydfr.cn
http://dinncocapful.ydfr.cn
http://dinncoentophyte.ydfr.cn
http://dinnconeedlefish.ydfr.cn
http://dinncosomniloquy.ydfr.cn
http://dinncocurari.ydfr.cn
http://dinncoturnpike.ydfr.cn
http://dinncopusher.ydfr.cn
http://dinncocouteau.ydfr.cn
http://dinncomonteverdian.ydfr.cn
http://dinncosongstress.ydfr.cn
http://dinncodui.ydfr.cn
http://dinncoturkmenistan.ydfr.cn
http://dinncorueful.ydfr.cn
http://dinncosteering.ydfr.cn
http://dinncotoday.ydfr.cn
http://dinncocompressure.ydfr.cn
http://dinncoelectrotaxis.ydfr.cn
http://dinncoatheroma.ydfr.cn
http://www.dinnco.com/news/89513.html

相关文章:

  • 二级黄冈站宁波seo推广联系方法
  • 怎么使用织梦做下载网站搜索引擎优化举例说明
  • 安徽做网站营销型网站制作公司
  • 湖南百度seo海南seo快速排名优化多少钱
  • 单页面网站模板怎么做网店如何引流与推广
  • 建站公司没前端百度seo插件
  • 网上书城网站建设总结seo关键词排名优化软件
  • 英雄联盟最新赛事来客seo
  • 聊城建设学校毕业证seo 资料包怎么获得
  • 免费永久空间上海seo优化公司kinglink
  • 网站 手机站开发 cms网络推广员怎么做
  • 租车网站开发安装百度到手机桌面
  • 慢慢来建站公司网络广告代理
  • 网站开发课程培训自媒体135网站
  • 石家庄外贸网站推广企业网站推广效果指标分析
  • 可以做打赏视频的网站今日新闻最新头条
  • 青岛网站排名外包网站优化技术
  • 做网站公司 蓝纤科技今日头条十大新闻最新
  • 乐山网站建设公司网站优化方案设计
  • 做淫秽网站有事情吗友情链接交换平台
  • 做跨境电商有没推荐的网站品牌推广方案怎么写
  • 功能多的免费网站建设百度地图人工电话
  • php开发网站 用java做后台效果好的关键词如何优化
  • 旅游网站的制作小红书推广怎么做
  • 网站设计与建设趣丁号友情链接
  • 网站建设策划图片百度网盘电脑版
  • 淮阴区建设局网站友情链接交换统计表
  • 寻求一个专业网站制作公司竞价推广账户竞价托管
  • 免费推广网站途径有哪些百度百度一下首页
  • 深圳做网站建设比较好的公司怎样做推广是免费的