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

搭建网站的架构南昌有做网站的吗

搭建网站的架构,南昌有做网站的吗,wordpress文件上传类型,情侣做记录网站源码文章目录前言一、AOP的底层实现原理二、AOP的两种开发模式1.使用xml配置文件1.1 添加AOP依赖1.2 创建UserService1.3创建UserServiceImpl1.4创建通知类1.5 创建applicationContext.xml#xff08;添加aop约束#xff09;1.6 测试2.使用注解开发2.1 创建bean.xml文件配置注解方… 文章目录前言一、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文件配置注解方式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依赖 dependenciesdependencygroupIdorg.springframework/groupIdartifactIdspring-context/artifactIdversion5.3.20/version/dependencydependencygroupIdorg.aspectj/groupIdartifactIdaspectjweaver/artifactIdversion1.9.9.1/version/dependencydependencygroupIdjunit/groupIdartifactIdjunit/artifactIdversion4.13.2/versionscopecompile/scope/dependency/dependencies1.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 version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocationhttp://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 iduserService classcom.wmj.service.impl.UserServiceImpl/bean!-- 通知 --bean idmyAdvice classcom.wmj.advice.MyAdvice/bean!-- aop --!-- 默认使用JDK动态代理 --!-- proxy-target-classtrue 使用cglib --aop:config proxy-target-classtrue!-- 配置切入点 切入点表达式的写法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 idpc expressionexecution(public void com.wmj.service.impl.UserServiceImpl.add())/--aop:pointcut idpc expressionexecution(* com.wmj.service.impl.*ServiceImpl.*(..))/!-- 切面 --aop:aspect refmyAdvice!-- 配置前置通知对应的方法 --aop:before methodbefore pointcut-refpc/aop:before!-- 配置后置通知最终通知对应的方法 --aop:after methodafter pointcut-refpc/aop:after!-- 配置后置通知对应的方法发生异常不执行 --aop:after-returning methodafter_returning pointcut-refpc/aop:after-returning!-- 配置异常通知对应的方法发生异常执行 --aop:after-throwing methodafter_throwing pointcut-refpc/aop:after-throwing!-- 配置环绕通知对应的方法 --aop:around methodaround pointcut-refpc/aop:around/aop:aspect/aop:config/beans1.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 version1.0 encodingUTF-8? beans xmlnshttp://www.springframework.org/schema/beansxmlns:xsihttp://www.w3.org/2001/XMLSchema-instancexmlns:aophttp://www.springframework.org/schema/aop xsi:schemaLocationhttp://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 iduserService classcom.wmj.service.impl.UserServiceImpl/bean!-- 2.配置通知对象 --bean idmyAdvice classcom.wmj.advice.MyAdvice/bean!-- 3.开启使用注解完成织入 --aop:aspectj-autoproxy/aop:aspectj-autoproxy/beans2.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.w-s-a.com/news/939984/

相关文章:

  • 物流的网站模板wordpress网站 800cdn
  • 建站公司合肥做精品课程网站需要啥素材
  • 成都三合一网站建设网站建设教程自学网
  • 门户网站跳出率wordpress火车头采集教程
  • 天津做网站的网络公司wordpress免费的模板
  • 有哪些关于校园内网站建设的法律如何申请免费网站空间
  • 玉溪市网站建设龙口网页定制
  • 网站开发都用什么软件上海景观设计公司10强
  • 网站建设氵金手指下拉十二深圳网站建设售后服务
  • 上海网站设计价青海企业网站制作
  • 静态网站做新闻系统深圳外贸网站建设哪家好
  • 网站如何做词360免费wifi老是掉线怎么办
  • 网站建设分金手指排名十八iis10 wordpress
  • 成都网站优化公司哪家好网站建设帮助中心
  • 做外单什么网站好佛山市建设企业网站服务机构
  • 哪些网站是单页面应用程序北京门头沟山洪暴发
  • 织梦(dedecms)怎么修改后台网站默认"织梦内容管理系统"标题关键词优化收费标准
  • 网站设计和备案企业官网网站建设免费
  • 公司概况-环保公司网站模板搜索引擎营销的基本流程
  • 门户网站建设经验天津市建设银行租房网站
  • 百度推广 帮做网站吗怎样修改网站的主页内容
  • 网站怎么做dns解析公司官网改版方案
  • 湛江市住房和城乡建设局网站杭州网站公司哪家服务好
  • 设计网站公司湖南岚鸿设计镜像的网站怎么做排名
  • 你注册过哪些网站微信app下载安装官方版2019
  • 杭州滨江的网站建设公司人才招聘网网站策划方案
  • 门户网站是指提供什么的网站网站优化需要工具
  • 和小男生做的网站代理公司注册步骤
  • 天猫网站建设的目标是什么seo有些什么关键词
  • 网站前端建设都需要什么莱芜信息港网页