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

标准网站建设报价单成都 网站建设 公司哪家好

标准网站建设报价单,成都 网站建设 公司哪家好,电子商务与网络营销题库,滨州网站建设报价SpringAOP是什么#xff1f;为什么要有SpringAOP#xff1f; 原文#xff1a;SpringAOP是什么#xff1f;为什么要有SpringAOP#xff1f; 一、有SpringAOP之前 简单的开发场景#xff0c;只需要写简单的业务逻辑#xff0c;比如CRUD 但是在执行具体的逻辑之前…SpringAOP是什么为什么要有SpringAOP 原文SpringAOP是什么为什么要有SpringAOP 一、有SpringAOP之前 简单的开发场景只需要写简单的业务逻辑比如CRUD 但是在执行具体的逻辑之前需要进行权限校验或者在具体的逻辑之后需要日志记录呢 这样就增加了很多代码而且增加的这些代码都是差不多的 既然如此那我们抽出来吧在这个类里面写一个私有的方法。 代码少了很多但是如果其他的类也需要用到权限校验和日志记录呢 难道也要在其他类里面写私有方法吗这也太麻烦了。 为了解决这个问题有两种方法。 第一种将这个私有方法抽出来不就好了我直接写两个工具类一个是权限校验一个是日志记录谁用谁调用。 第二种我直接搞一个父类谁用我就让它继承这个父类这样就能直接调用父类的方法。 但是不论是第一种还是第二种其实都会侵入业务类的方法逻辑那么有没有一种方法能在没有对业务核心代码侵入性的前提下给业务核心代码添加额外的功能呢 这时候AOP就出来了也就是所谓的面向切面编程。 首先来看一下AOP的概念 切入点 想额外添加功能的方法 切面 权限检查、日志记录等这些增强逻辑的方法在的类 通知 在目标方法运行的什么时机来执行某个增强逻辑 目标方法前还是目标方法后 切入点表达式 规定增强逻辑需要去增强什么方法 二、有SpringAOP之后 使用方法 maven依赖 dependencies!--导入Spring Context核心依赖--dependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.3.23/version/dependency!--Spring AOP--dependencygroupIdorg.springframework/groupIdartifactIdspring-aspects/artifactIdversion5.3.1/version/dependency!--Lombok--dependencygroupIdorg.projectlombok/groupIdartifactIdlombok/artifactIdversion1.18.30/version/dependency!--Junit单元测试--dependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.13.2/versionscopetest/scope/dependency/dependencies切入点 package com.moon.aop.bean;/*** Author moon* Date 2023/10/15 15:55* Description 切入点*/ public class UserService {public void addUser() {System.out.println(添加用户...);}public void queryUser() {System.out.println(查询用户...);}public void editUser() {System.out.println(编辑用户...);}public void deleteUser() {System.out.println(删除用户...);} } 切面 package com.moon.aop.bean;/* * 底层依赖Aspect的注解【但是原理不同】 * */ import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Pointcut;/*** Author moon* Date 2023/10/15 15:58* Description 切面里面放的增强逻辑*/Aspect public class UserAspect {/** 这就是传说中上文所谓的切入点表达式* */Pointcut(value execution(* com.moon.aop.bean.UserService.*(..)))public void point() {}/** 这就是增强逻辑* Before、After就是所谓的通知* */Before(value point())public void beforeRun() {System.out.println(在目标方法执行前开始执行);}After(value point())public void afterRun() {System.out.println(在目标方法执行后开始执行);} } 配置类用来初始化和加载Spring的IOC容器 package com.moon.aop.bean;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy;/*** Author moon* Date 2023/10/15 16:07* Description 用该类来初始化和加载IOC容器*/Configuration public class SpringConfig {Beanpublic UserAspect userAspect() {return new UserAspect();}Beanpublic UserService userService() {return new UserService();} } Junit单元测试 import com.moon.aop.bean.SpringConfig; import com.moon.aop.bean.UserService; import org.junit.Test; import org.springframework.context.annotation.AnnotationConfigApplicationContext;/*** Author moon* Date 2023/10/15 16:32* Description*/ public class AOPTest {Testpublic void test01() {/** 通过配置类初始化IOC容器* */AnnotationConfigApplicationContext context new AnnotationConfigApplicationContext(SpringConfig.class);/** 获取目标对象Bean* */UserService userService context.getBean(UserService.class);userService.addUser();} } AOP并没有生效 此时userService.getClass().getName()的值为 那是因为Spring并没有开启AOP需要我们手动开启 package com.moon.aop.bean;import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy;/*** Author moon* Date 2023/10/15 16:07* Description 用该类来初始化和加载IOC容器*/Configuration /* * 手动开启AOP功能 * */ EnableAspectJAutoProxy public class SpringConfig {Beanpublic UserAspect userAspect() {return new UserAspect();}Beanpublic UserService userService() {return new UserService();} } 成功 此时userService.getClass().getName()的值为
http://www.pierceye.com/news/606330/

相关文章:

  • 企业网站建设所需要的资料网站备案 icp备案
  • 商城类网站方案中国风 wordpress主题
  • 网站更换服务器教程南阳网站推广招聘
  • 海尔网站的建设目标四库一平台个人信息查询
  • 佛山市建设网站公司网站手机端和电脑端
  • 属于c2c的网站是重庆化工建设信息网站
  • 高端大气网站推荐网赌网站建设多少钱
  • 宁波网站关键词优化排名网站修改图片怎么做
  • 苏州网站建设案例购买网站域名
  • 自己做剧本网站重庆建设工业公司官网
  • 中国网站建设中心建网站和开发软件哪个难
  • 优化网站被百度屏阿里云网站备案核验单
  • 肇庆做网站哪家好河北建设工程信息网正规网站
  • 怎么做展示网站公司网站管理规定
  • 娄底网站制作备案号查询平台
  • 青岛网站排名方案优化的定义
  • 微网站开发外包杨浦做网站公司
  • 网站推广服务包括哪些个人简历网官网免费
  • 铜仁住房和城乡建设局网站安贞做网站公司
  • 做网站客户尾款老不给怎么办东莞市研发网站建设品牌
  • 文化网站策划wordpress iscategory
  • 北京社区网站建设wordpress主题 sen
  • 做外贸商城网站重庆seo整站优化方案范文
  • 做AI免费网站wordpress 论坛app
  • 东阿网站建设产品芜湖网络科技有限公司
  • 提供网站技术北京中小企业公司名单
  • 专业的建站公司都具备什么条件凡科建站收费价目表
  • 修改网站主目录的位置wordpress商品展示模板
  • 微信微网站是什么案例天津室内设计培训
  • 如何做网站网页广州海珠网站开发设计