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

网站建设市场前景怎样在百度上做广告推广

网站建设市场前景,怎样在百度上做广告推广,企业网站可以免费做吗,长沙房地产集团文章目录前言一、AOP的底层实现原理二、AOP的两种开发模式1.使用xml配置文件1.1 添加AOP依赖1.2 创建UserService1.3创建UserServiceImpl1.4创建通知类1.5 创建applicationContext.xml(添加aop约束)1.6 测试2.使用注解开发2.1 创建bean.xml文件配置注解方…

文章目录

  • 前言
  • 一、AOP的底层实现原理
  • 二、AOP的两种开发模式
    • 1.使用xml配置文件
      • 1.1 添加AOP依赖
      • 1.2 创建UserService
      • 1.3创建UserServiceImpl
      • 1.4创建通知类
      • 1.5 创建applicationContext.xml(添加aop约束)
      • 1.6 测试
    • 2.使用注解开发
      • 2.1 创建bean.xml文件配置注解方式
      • 2.2 在通知类上使用相关注解
      • 2.3 测试
  • 总结


前言

spring的核心是IOC(控制反转)和AOP(面向切面编程)。AOP面向切面编程是通过预编译方式和运行期间动态代理实现程序功能的统一维护的一种技术。AOP是OOP的延续,是软件开发中的一个热点,也是Spring框架中的一个重要内容,是函数式编程的一种衍生范型。利用AOP可以对业务逻辑的各个部分进行隔离,从而使得业务逻辑各部分之间的耦合度降低,提高程序的可重用性,同时提高了开发的效率。


一、AOP的底层实现原理

此处再解释,详情请看我这篇文章
静态代理和动态代理https://blog.csdn.net/l_zl2021/article/details/127095878

二、AOP的两种开发模式

关于AOP的案例,看我这边篇文章,本文只是记录两种AOP开发方式
AOP初识https://blog.csdn.net/l_zl2021/article/details/127113425

1.使用xml配置文件

1.1 添加AOP依赖

<dependencies><dependency><groupId>org.springframework</groupId><artifactId>spring-context</artifactId><version>5.3.20</version></dependency><dependency><groupId>org.aspectj</groupId><artifactId>aspectjweaver</artifactId><version>1.9.9.1</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.13.2</version><scope>compile</scope></dependency></dependencies>

1.2 创建UserService

package com.wmj.service;//目标对象target
public interface UserService {//未增强的方法叫做连接点JoinPoint//已增强的方法叫做切入点PointCutpublic void add();public void delete();
}

1.3创建UserServiceImpl

代码如下(示例):

package com.wmj.service.impl;import com.wmj.service.UserService;public class UserServiceImpl implements UserService {@Overridepublic void add() {System.out.println("添加用户..");//int i = 1/0;}@Overridepublic void delete() {System.out.println("删除用户..");}
}

1.4创建通知类

前置通知(before):目标方法运行之前调用
后置通知(after-returning):在目标方法运行之后调用 (如果出现异常不会调用)
环绕通知(around):在目标方法之前和之后都调用(ProceedingJoinPoint对象 -->> 调用proceed方法)
异常拦截通知(after-throwing):如果出现异常,就会调用
最终通知(after):在目标方法运行之后调用 (无论是否出现 异常都会调用)

package com.wmj.advice;import org.aspectj.lang.ProceedingJoinPoint;//通知类,增强的代码(方法)Advice
public class MyAdvice {public void before(){System.out.println("前置通知,目标对象调用方法前执行");}public void after(){System.out.println("后置通知(最终通知),目标对象调用方法后执行,无论是否发生异常都执行");}public void after_returning(){System.out.println("后置通知,目标对象调用方法后执行,发生异常不执行");}public void after_throwing(){System.out.println("异常通知,发生异常执行");}public void around(ProceedingJoinPoint joinPoint) throws Throwable {System.out.println("环绕通知,目标对象调用方法之前");joinPoint.proceed();System.out.println("环绕通知,目标对象调用方法之后");}}

1.5 创建applicationContext.xml(添加aop约束)

<?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: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/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- bean definitions here --><bean id="userService" class="com.wmj.service.impl.UserServiceImpl"></bean><!-- 通知 --><bean id="myAdvice" class="com.wmj.advice.MyAdvice"></bean><!-- aop --><!-- 默认使用JDK动态代理 --><!-- proxy-target-class="true" 使用cglib --><aop:config proxy-target-class="true"><!-- 配置切入点 切入点表达式的写法:execution(表达式)public void com.abyg.service.UserServiceImpl.save() void com.wmj.service.UserServiceImpl.save()  其他修饰符无返回值的save空参方法* com.wmj.service.UserServiceImpl.save()  有或者无返回值的save空参方法* com.wmj.service.UserServiceImpl.*()  有或者无返回值的所有空参方法* com.wmj.service.*ServiceImpl.*(..)  有或者无返回值的所有有参或者空参方法* com.wmj.service..*ServiceImpl.*(..)  一般不用,service包下的子包和孙包以ServiceImpl结尾的类中的方法
--><!-- 切入点 -->
<!--                <aop:pointcut id="pc" expression="execution(public void com.wmj.service.impl.UserServiceImpl.add())"/>--><aop:pointcut id="pc" expression="execution(* com.wmj.service.impl.*ServiceImpl.*(..))"/><!-- 切面 --><aop:aspect ref="myAdvice"><!-- 配置前置通知对应的方法 --><aop:before method="before" pointcut-ref="pc"></aop:before><!-- 配置后置通知(最终通知)对应的方法 --><aop:after method="after" pointcut-ref="pc"></aop:after><!-- 配置后置通知对应的方法,发生异常不执行 --><aop:after-returning method="after_returning" pointcut-ref="pc"></aop:after-returning><!-- 配置异常通知对应的方法,发生异常执行 --><aop:after-throwing method="after_throwing" pointcut-ref="pc"></aop:after-throwing><!-- 配置环绕通知对应的方法 --><aop:around method="around" pointcut-ref="pc"></aop:around></aop:aspect></aop:config></beans>

1.6 测试

package com.wmj.test;import com.wmj.service.UserService;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;public class SpringTest {@Testpublic void testUserService(){ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("applicationContext.xml");UserService userService = (UserService)applicationContext.getBean("userService");userService.add();userService.delete();}}

2.使用注解开发

2.1 创建bean.xml文件配置注解方式

<?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: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/aop http://www.springframework.org/schema/aop/spring-aop.xsd"> <!-- bean definitions here --><!-- 准备工作: 导入aop(约束)命名空间 --><!-- 1.配置目标对象 --><bean id="userService" class="com.wmj.service.impl.UserServiceImpl"></bean><!-- 2.配置通知对象 --><bean id="myAdvice" class="com.wmj.advice.MyAdvice"></bean><!-- 3.开启使用注解完成织入 --><aop:aspectj-autoproxy></aop:aspectj-autoproxy></beans>

2.2 在通知类上使用相关注解

@Aspect
//表示该类是一个通知类
//通知类,增强的代码(方法)Advice
public class MyAdvice {//自己设置一个切点,管理重复代码@Pointcut("execution(* com.wmj.service.impl.*ServiceImpl.*(..))")public void pc(){}//前置通知//指定该方法是前置通知,并制定切入点@Before("MyAdvice.pc()")public void before(){System.out.println("前置通知,目标对象调用方法前执行");}//最终通知@After("execution(* com.wmj.service.impl.*ServiceImpl.*(..))")public void after(){System.out.println("后置通知(最终通知),目标对象调用方法后执行,无论是否发生异常都执行");}//后置通知@AfterReturning("execution(* com.wmj.service.impl.*ServiceImpl.*(..))")public void after_returning(){System.out.println("后置通知,目标对象调用方法后执行,发生异常不执行");}//异常通知@AfterThrowing("execution(* com.wmj.service.impl.*ServiceImpl.*(..))")public void after_throwing(){System.out.println("异常通知,发生异常执行");}//环绕通知@Around("execution(* com.wmj.service.impl.*ServiceImpl.*(..))")public void around(ProceedingJoinPoint joinPoint) throws Throwable {System.out.println("环绕通知,目标对象调用方法之前");joinPoint.proceed();System.out.println("环绕通知,目标对象调用方法之后");}}

2.3 测试

@Test
public void testUserService(){ClassPathXmlApplicationContext applicationContext =new ClassPathXmlApplicationContext("bean.xml");UserService userService = (UserService)applicationContext.getBean("userService");userService.add();userService.delete();
}

总结

本文记录了两种开发AOP编程的方式

http://www.khdw.cn/news/1907.html

相关文章:

  • 网站开发前后端分离是主流吗百度客服电话号码
  • 青浦门户网站万网注册域名查询官方网站
  • 视频网站点击链接怎么做的域名停靠
  • 长春网站建设百度客服电话24小时
  • 佛山网站的优化什么是信息流广告
  • 淘宝放单网站怎么做口碑营销是什么
  • 如何申请免费空间西安seo包年服务
  • 大兴网站制作推广普通话
  • 网站建设服务费怎么做会计分录品牌营销策划案例
  • 网站企业备案付费内容网站
  • 网站上线需要哪些步骤小程序开发系统
  • 上海有名的做网站的公司有哪些营销咨询公司排名
  • 云盘做网站文件seo关键词排名优化推荐
  • 四川做文学有关的网站个人免费网站建设
  • 东莞网站设计制作教程网上怎么做广告
  • 利用养生网站做竞价引流seo托管公司
  • 网站建设工作不足及整改正规seo排名外包
  • ppt的网站导航栏怎么做的nba西部排名
  • 怎么用dwcs6做网站设计网络营销成功的案例分析
  • 网站开发技术包括什么学技术包分配的培训机构
  • 手机wap网站的分析河北网站seo外包
  • 做网站图片大小好的搜索引擎推荐
  • 网站制作视频自己建网站需要多少钱
  • 深圳有效网站制作哪家公司好优化软件seo排名
  • 网站建设两个方面东莞优化排名推广
  • 有什么做兼职的好网站搜索引擎优化关键词
  • wordpress 网页特效seo技巧分享
  • 教育网站建设 培训网站建设网站优化最为重要的内容是
  • 嘉定做网站国际新闻稿件
  • 襄阳做网站找哪家公司腾讯云域名注册