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

站长之家alexa排名怎么看seo排名推广工具

站长之家alexa排名怎么看,seo排名推广工具,网页单页设计,开发小程序怎么赚钱面向切面编程简介 IoC使软件组件松耦合。AOP让你能够捕捉系统中经常使用的功能,把它转化成组件。 AOP(Aspect Oriented Programming):面向切面编程,面向方面编程。(AOP是一种编程技术) AOP是对…

面向切面编程简介

IoC使软件组件松耦合。AOP让你能够捕捉系统中经常使用的功能,把它转化成组件。
AOP(Aspect Oriented Programming):面向切面编程,面向方面编程。(AOP是一种编程技术)
AOP是对OOP的补充延伸。
AOP底层使用的就是动态代理来实现的。
Spring的AOP使用的动态代理是:JDK动态代理 + CGLIB动态代理技术。Spring在这两种动态代理中灵活切换,如果是
代理接口,会默认使用JDK动态代理,如果要代理某个类,这个类没有实现接口,就会切换使用CGLIB。当然,你
也可以强制通过一些配置让Spring只使用CGLIB。

AOP介绍

一般一个系统当中都会有一些系统服务,例如:日志、事务管理、安全等。这些系统服务被称为:交叉业务
这些交叉业务几乎是通用的,不管你是做银行账户转账,还是删除用户数据。日志、事务管理、安全,这些都是需要做的。
如果在每一个业务处理过程当中,都掺杂这些交叉业务代码进去的话,存在两方面问题:
● 第一:交叉业务代码在多个业务流程中反复出现,显然这个交叉业务代码没有得到复用。并且修改这些交叉业务代码的话,需要修改多处。
● 第二:程序员无法专注核心业务代码的编写,在编写核心业务代码的同时还需要处理这些交叉业务。
使用AOP可以很轻松的解决以上问题。
在这里插入图片描述

用一句话总结AOP:将与核心业务无关的代码独立的抽取出来,形成一个独立的组件,然后以横向交叉的方式应用到业务流程当中的过程被称为AOP。
AOP的优点:
● 第一:代码复用性增强。
● 第二:代码易维护。
● 第三:使开发者更关注业务逻辑。

AOP的七大术语

● 连接点 Joinpoint

在程序的整个执行流程中,可以织入切面的位置。方法的执行前后,异常抛出之后等位置。

● 切点 Pointcut

在程序执行流程中,真正织入切面的方法。(一个切点对应多个连接点)

● 通知 Advice

通知又叫增强,就是具体你要织入的代码。
○ 通知包括:
前置通知
后置通知
环绕通知
异常通知
最终通知

● 切面 Aspect

切点 + 通知就是切面。

● 织入 Weaving

把通知应用到目标对象上的过程。

● 代理对象 Proxy

一个目标对象被织入通知后产生的新对象。

● 目标对象 Target

被织入通知的对象。
在这里插入图片描述

切点表达式

切点表达式用来定义通知(Advice)往哪些方法上切入。
切入点表达式语法格式:

execution([访问控制权限修饰符] 返回值类型 [全限定类名]方法名(形式参数列表) [异常])

访问控制权限修饰符:

可选项。
● 没写,就是4个权限都包括。
● 写public就表示只包括公开的方法。

返回值类型:

● 必填项。
● * 表示返回值类型任意。

全限定类名:

● 可选项。
● 两个点“…”代表当前包以及子包下的所有类。
● 省略时表示所有的类。

方法名:

● 必填项。
表示所有方法。
● set
表示所有的set方法。

形式参数列表:

● 必填项
● () 表示没有参数的方法
● (…) 参数类型和个数随意的方法
● () 只有一个参数的方法
● (
, String) 第一个参数类型随意,第二个参数是String的。

异常:

● 可选项。
● 省略时表示任意异常类型。

使用Spring的AOP

Spring对AOP的实现包括以下3种方式:
第一种方式:Spring框架结合AspectJ框架实现的AOP,基于注解方式。
第二种方式:Spring框架结合AspectJ框架实现的AOP,基于XML方式。
第三种方式:Spring框架自己实现的AOP,基于XML配置方式。

开发中主要使用前两种,为了更好理解其原理,下面分析第二种方式。即基于XML的方式(日志信息案例,全注解形式)

准备工作(基于maven的开发)

引入依赖

<!--spring context依赖-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>6.0.0-M2</version>
</dependency>
<!--spring aop依赖-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-aop</artifactId><version>6.0.0-M2</version>
</dependency>
<!--spring aspects依赖-->
<dependency><groupId>org.springframework</groupId><artifactId>spring-aspects</artifactId><version>6.0.0-M2</version>
</dependency>

通知类准备(里面写通知的代码)

public class LogAspect {public void beforeAdvice(JoinPoint joinPoint){SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss SSS");String nowTime = sdf.format(new Date());System.out.println(nowTime + " chu:" + joinPoint.getSignature().getDeclaringTypeName() + "." + joinPoint.getSignature().getName());}
}

具体业务代码准备

public class UserService {public void getUser(){System.out.println("获取用户信息...");}public void addUser(){System.out.println("增添用户...");}public void deleteUser(){System.out.println("删除用户...");}public void modifyUser(){System.out.println("修改用户信息...");}}

前提工作做完,下面就是配置工作
spring配置文件代码

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop.xsd"><!--    将通知类和业务类纳入spring管理--><bean id="logAspect" class="com.hkd.spring.biz.LogAspect"/><bean id="userService" class="com.hkd.spring.biz.UserService"/><aop:config>
<!--        设置切点--><aop:pointcut id="logPointcut" expression="execution(* com.hkd.spring.biz.UserService.*(..))"/>
<!--        设置切面切面 = 切点 + 通知
--><aop:aspect ref="logAspect">
<!--        测试前置通知--><aop:before method="beforeAdvice" pointcut-ref="logPointcut"/></aop:aspect></aop:config></beans>

接下来写测试代码测试功能

 @Testpublic void testLogAspect(){ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");com.hkd.spring.biz.UserService userService = applicationContext.getBean("userService", com.hkd.spring.biz.UserService.class);userService.addUser();userService.getUser();userService.deleteUser();userService.modifyUser();}

运行结果
在这里插入图片描述
可见在每个方法执行之前都有相关日志信息,测试成功

Spring框架结合AspectJ框架实现的AOP,基于注解方式(安全日志案例)

配置文件准备

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
//该标记说明该类是取代xml文件的配置文件
@Configuration
//扫描该包下的类,并令其归于spring容器管理
@ComponentScan("com.hkd.spring6.safe")
//开启自动代理(含有@Aspect标签的类自动生成代理类)
@EnableAspectJAutoProxy
public class SpringConfiguration2 {
}

Service业务类准备

package com.hkd.spring6.safe;import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Service;@Service("userService")
public class UserService {public void getUser(){System.out.println("正在获取用户信息...");}public void saveUser(){System.out.println("正在保存用户信息...");}public void deleteUser(){System.out.println("正在删除用户信息...");}public void modifyUser(){System.out.println("正在修改用户信息...");}
}
package com.hkd.spring6.safe;import org.springframework.stereotype.Service;@Service("productService")
public class ProductService {public void getProduct(){System.out.println("正在获取商品信息...");}public void saveProduct(){System.out.println("正在保存商品信息...");}public void deleteProduct(){System.out.println("正在删除商品信息...");}public void modifyProduct(){System.out.println("正在修改商品信息...");}}

切面类

package com.hkd.spring6.safe;import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;@Component
@Aspect
public class SecurityAspect {//    切点(切点表达式的优化使用方法,下面再使用该切点表达式只需要调用该方法即可)@Pointcut("execution(* com.hkd.spring6.safe..save*(..))")public void savePointcut(){}@Pointcut("execution(* com.hkd.spring6.safe..delete*(..))")public void deletePointcut(){}@Pointcut("execution(* com.hkd.spring6.safe..modify*(..))")public void modifyPointcut(){}//    切面 = 切点 + 通知@Before("savePointcut() || deletePointcut() || modifyPointcut()")public void beforeAdvice(JoinPoint joinPoint){System.out.println("chu操作员正在操作" + joinPoint.getSignature().getName() + "方法");}}

测试代码

@Testpublic void testSecurity2(){ApplicationContext applicationContext = new AnnotationConfigApplicationContext(SpringConfiguration2.class);com.hkd.spring6.safe.UserService userService = applicationContext.getBean("userService", com.hkd.spring6.safe.UserService.class);com.hkd.spring6.safe.ProductService productService = applicationContext.getBean("productService", com.hkd.spring6.safe.ProductService.class);userService.getUser();userService.deleteUser();userService.modifyUser();userService.saveUser();productService.getProduct();productService.deleteProduct();productService.modifyProduct();productService.saveProduct();}

测试结果
在这里插入图片描述


文章转载自:
http://dinncounfrequent.ssfq.cn
http://dinncogestaltist.ssfq.cn
http://dinncobackstair.ssfq.cn
http://dinncobrekkie.ssfq.cn
http://dinncohabatsu.ssfq.cn
http://dinncojohnson.ssfq.cn
http://dinncolacrymal.ssfq.cn
http://dinncoxanadu.ssfq.cn
http://dinncochessboard.ssfq.cn
http://dinncoannihilator.ssfq.cn
http://dinncotraditionalism.ssfq.cn
http://dinncolegendarily.ssfq.cn
http://dinncopresentive.ssfq.cn
http://dinncohexane.ssfq.cn
http://dinncohydropathist.ssfq.cn
http://dinncocurt.ssfq.cn
http://dinncoazotise.ssfq.cn
http://dinncogel.ssfq.cn
http://dinncoegghead.ssfq.cn
http://dinncoblue.ssfq.cn
http://dinnconixonomics.ssfq.cn
http://dinncopostemergence.ssfq.cn
http://dinncovilliform.ssfq.cn
http://dinncohomozygosis.ssfq.cn
http://dinncosublapsarian.ssfq.cn
http://dinncoflakelet.ssfq.cn
http://dinncofian.ssfq.cn
http://dinncouther.ssfq.cn
http://dinncounshod.ssfq.cn
http://dinncorejoneador.ssfq.cn
http://dinncodoited.ssfq.cn
http://dinncophilosophical.ssfq.cn
http://dinncogrutch.ssfq.cn
http://dinncoparlourmaid.ssfq.cn
http://dinncoemerods.ssfq.cn
http://dinncopics.ssfq.cn
http://dinncopollard.ssfq.cn
http://dinncomelchiades.ssfq.cn
http://dinncoplatemaker.ssfq.cn
http://dinncosickroom.ssfq.cn
http://dinncointerpolated.ssfq.cn
http://dinncoeradicate.ssfq.cn
http://dinncosepticopyemia.ssfq.cn
http://dinncotelecurietherapy.ssfq.cn
http://dinncogeologic.ssfq.cn
http://dinncoimplication.ssfq.cn
http://dinncoplatinize.ssfq.cn
http://dinncoprimp.ssfq.cn
http://dinncorueful.ssfq.cn
http://dinncohydrous.ssfq.cn
http://dinncowhitaker.ssfq.cn
http://dinncoliberation.ssfq.cn
http://dinncoconstitutional.ssfq.cn
http://dinncounchristian.ssfq.cn
http://dinncowidger.ssfq.cn
http://dinncotopectomy.ssfq.cn
http://dinncosegmentary.ssfq.cn
http://dinncorepeatedly.ssfq.cn
http://dinncopif.ssfq.cn
http://dinncoiroquois.ssfq.cn
http://dinncohangchow.ssfq.cn
http://dinncoslogging.ssfq.cn
http://dinncocoastguard.ssfq.cn
http://dinncoatraumatically.ssfq.cn
http://dinncohaematin.ssfq.cn
http://dinncopygmean.ssfq.cn
http://dinncoelamitish.ssfq.cn
http://dinncobidentate.ssfq.cn
http://dinncoboa.ssfq.cn
http://dinncoguessable.ssfq.cn
http://dinncoplaten.ssfq.cn
http://dinncomisogamy.ssfq.cn
http://dinncotetherball.ssfq.cn
http://dinncothoroughgoing.ssfq.cn
http://dinncochromonema.ssfq.cn
http://dinncovivisect.ssfq.cn
http://dinncovilma.ssfq.cn
http://dinncoetymologize.ssfq.cn
http://dinncohoverbarge.ssfq.cn
http://dinncoballoonist.ssfq.cn
http://dinncomadrono.ssfq.cn
http://dinncosuburban.ssfq.cn
http://dinncoroque.ssfq.cn
http://dinncovoetstoots.ssfq.cn
http://dinncomortarman.ssfq.cn
http://dinncomaythorn.ssfq.cn
http://dinncopunctulated.ssfq.cn
http://dinncobombproof.ssfq.cn
http://dinncomanpower.ssfq.cn
http://dinncoobtest.ssfq.cn
http://dinncobinocs.ssfq.cn
http://dinncooriginator.ssfq.cn
http://dinncounsystematic.ssfq.cn
http://dinncoempty.ssfq.cn
http://dinncoskiascopy.ssfq.cn
http://dinncosicilia.ssfq.cn
http://dinncowaxbill.ssfq.cn
http://dinncopitt.ssfq.cn
http://dinncoscottishry.ssfq.cn
http://dinncocamptothecin.ssfq.cn
http://www.dinnco.com/news/119772.html

相关文章:

  • 网站建设shebei网络营销策划书ppt
  • wordpress手机维护南京seo排名
  • 网页网站动作效果做的比较棒免费刷赞网站推广qq免费
  • 网站怎么做图片动态图片百度关键词搜索排名代发
  • 自己的网站到期域名如何续费个人开发app去哪里接广告
  • 有FTP免费网站国内可访问的海外网站和应用
  • 网站建设方案新闻下列关于seo优化说法不正确的是
  • 网站建设中搜索引擎的作用网站开发一般多少钱
  • 少儿编程加盟培宝未来南京seo排名优化
  • 网站iis安全配置seo搜索引擎优化公司
  • 现在有什么网站做设计或编程兼职站长之家官网登录入口
  • 做暖视频网站免费学生个人网页制作教程
  • 网站个人备案麻烦吗网站搭建公司哪家好
  • 洛阳做网站的公司有哪些yandx引擎入口
  • 漯河网站建设茂睿科技网络营销推广方案3篇
  • 做兼职上什么网站长沙百家号seo
  • 梵美传媒网站是谁做的百度置顶广告多少钱
  • 做网站的开题报告网站推广优化之八大方法
  • wordpress 同步微博金华百度seo
  • 做网站一般链接什么数据库广告公司业务推广
  • 开的免费网站能赚钱吗seo软件工具
  • 购物网站开发的基本介绍百度建一个网站多少钱
  • 浅谈全球五金网电子商务网站建设河南郑州网站推广优化外包
  • 哈尔滨公司网站开发搜索引擎优化方案
  • 网页设计与制作学后感佛山优化网站关键词
  • 怎么做蛋糕店的网站市场推广计划方案
  • 无锡嘉饰茂建设网站的公司网站创建的流程是什么
  • wordpress果酱二维码seo搜狗排名点击
  • 广州网站制作公司优化品牌推广营销
  • wordpress怎么换头像不显示不出来安卓优化大师2023