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

网站建设需要几个人成都哪个公司做网站

网站建设需要几个人,成都哪个公司做网站,学网站建设与管理有用吗,.net 网站开发工程师前言 接触过Spring的都知道#xff0c;aop是其中重要的特性之一。笔者在开发做项目中#xff0c;aop更多地是要和注解搭配#xff1a;在某些方法上加上自定义注解#xff0c;然后要对这些方法进行增强(很少用execution指定#xff0c;哪些包下的哪些方法要增强)。那这时就…前言 接触过Spring的都知道aop是其中重要的特性之一。笔者在开发做项目中aop更多地是要和注解搭配在某些方法上加上自定义注解然后要对这些方法进行增强(很少用execution指定哪些包下的哪些方法要增强)。那这时就要引出annotation、target、within了。我们一一讲解。 annotation 方法上是否有指定注解子类调用不重写的方法会被aop拦截调用重写的方法看是否加了指定注解。 首先引入依赖 dependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-aop/artifactIdversion2.7.4/version /dependencydependencygroupIdorg.springframework.boot/groupIdartifactIdspring-boot-starter-test/artifactIdversion2.7.4/versionscopetest/scope /dependency自定义一个注解 import java.lang.annotation.Target; import java.lang.annotation.*;Target({ElementType.METHOD, ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented public interface Outer {int limit() default 0;}目标类 import org.springframework.stereotype.Component;Component public class Target {Outer(limit 8)public void invoke() {System.out.println(执行Target的方法);}}Component public class SonTarget extends Target {}切面类 import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import java.lang.reflect.Method;Component Aspect public class MyAspect {Around(annotation(com.gs.spring_boot_demo.aop.Outer))public Object around(ProceedingJoinPoint point) throws Throwable {Method method ((MethodSignature)point.getSignature()).getMethod();Outer outer method.getAnnotation(Outer.class);System.out.println(aop前置 outer.limit());return point.proceed();}}编写测试类 import org.springframework.boot.test.context.SpringBootTest; import javax.annotation.Resource; import org.springframework.beans.factory.annotation.Autowired; import org.junit.jupiter.api.Test;SpringBootTest public class AopTest {Resourceprivate Target target;Autowiredprivate SonTarget sonTarget;Testpublic void aop() {target.invoke();System.out.println(---);sonTarget.invoke();}}运行aop方法打印结果 把子类SonTarget修改一下 import org.springframework.stereotype.Component;Component public class SonTarget extends Target {public void invoke() {System.out.println(子类执行Target的方法);}}再次运行测试类这时子类的invoke()方法不会被拦截了 当然如果SonTarget的invoke()方法上加上Outer那就能被aop拦截了。 target 调用方法的对象所属的类上是否有指定注解注解被Inherited修饰子类调用会生效无Inherited看子类上有无该注解。 自定义注解不动目标类修改为 import org.springframework.stereotype.Component;Component Outer(limit 8) public class Target {public void invoke() {System.out.println(执行Target的方法);}}import org.springframework.stereotype.Component;Component public class SonTarget extends Target {public void invoke() {System.out.println(子类执行Target的方法);}}切面类修改为 import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import java.lang.reflect.Method;Component Aspect public class MyAspect {/*** 要注意一下target很硬霸所有的bean都会被动态代理(不管类上有没有加自定* 义注解)所以要约束为本项目下的包下* 不然测试用例运行时会报错依赖中有些类是final的被动态代理会报错*/Around(target(com.gs.spring_boot_demo.aop.Outer) within(com.gs.spring_boot_demo..*))public void around(ProceedingJoinPoint point) throws Throwable {Method method ((MethodSignature)point.getSignature()).getMethod();Outer outer method.getDeclaringClass().getAnnotation(Outer.class);System.out.println(aop前置 outer.limit());point.proceed();}}测试类不动运行 SonTarget的invoke()没有被拦截想要被拦截就在SonTarget类上添加Outer或者自定义注解上增加Inherited(表明父类加上该注解后子类能够继承) import java.lang.annotation.Target; import java.lang.annotation.*;Target({ElementType.METHOD, ElementType.TYPE}) Retention(RetentionPolicy.RUNTIME) Documented Inherited public interface Outer {int limit() default 0;}within 方法所属的类上是否有指定注解注解没有被Inherited修饰子类调用不重写的方法会被拦截调用重写的方法看子类上是否有注解注解被Inherited修饰子类调用方法都会被拦截不管是否重写 自定义注解改一下就把修饰它的Inherited去掉   目标类 import org.springframework.stereotype.Component;Component Outer(limit 8) public class Target {public void invoke() {System.out.println(执行Target的方法);}}import org.springframework.stereotype.Component;Component public class SonTarget extends Target {}切面类修改为 import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.reflect.MethodSignature; import org.springframework.stereotype.Component; import java.lang.reflect.Method;Component Aspect public class MyAspect {Around(within(com.gs.spring_boot_demo.aop.Outer))public void around(ProceedingJoinPoint point) throws Throwable {Method method ((MethodSignature)point.getSignature()).getMethod();Outer outer method.getDeclaringClass().getAnnotation(Outer.class);System.out.println(aop前置 outer.limit());point.proceed();}}测试类不动运行 子类的方法能被拦截我们把子类的方法重写一下 import org.springframework.stereotype.Component;Component public class SonTarget extends Target {public void invoke() {System.out.println(子类执行Target的方法);}}再次运行测试类打印出结果 子类的方法没有被拦截想要被拦截SonTarget类上加上Outer。 我们再试一下自定义注解被Inherited修饰的情况。Outer注解加上Inherited然后Target不动SonTarget也不动(重写了invoke()方法类上也没有Outer)运行测试类 SonTaget改一下不重写invoke()方法运行测试类
http://www.hkea.cn/news/14276000/

相关文章:

  • 网站没备案可以访问吗长链接生成短链接网址
  • 做网站开票内容是什么抖音代运营业务介绍
  • 分类信息网站怎么做深圳正规装修公司
  • 做床上用品网站wordpress教育类主题
  • 网站备案核验单怎么填深圳做门户网站的网络公司
  • 淄博建设企业网站厦门模板做网站
  • 旅行社网站建设规划精品网站建设费用 磐石网络
  • 亚马逊网站入口如何做网站海报
  • 台州做网站的公司有哪些公司wordpress 仪表盘
  • 山东青岛网站建设seo优化wordpress如何设置目录权限设置
  • 网站开发证有没有用怎么做找优惠券的网站
  • 西安做网站选哪家好怎么自己做网址
  • 葫芦岛建设工程信息网站安徽省建设厅网站资料下载
  • 全国icp网站备案审核时间许昌网络推广哪家好
  • 网站建设技术app下载安心保险官方网站
  • 海口自助建站软件网站做网站
  • 龙华民治网站建设揭阳企业建站程序
  • 东莞p2p网站开发费用宁波公司地址
  • 贵州城乡和住房建设厅网站审批电脑怎做单页网站
  • 商城网站怎么做的最近国内新闻大事20条
  • 网站建设个人简历社交媒体营销三种方式
  • 望城经开区建设开发公司门户网站怎么用支付宝做发卡网站
  • 方案案例网站ai一键生成短视频免费版
  • 创世网站建设公司在中国做国外网站
  • 2021能看的网站不要app贴吧做画册的国外网站
  • 十个实用网站网址建设网站成都
  • 笔记本怎么建设网站值得买wordpress
  • 国外营销网站政务公开网站建设意义
  • 网站建设发展的前景简洁的公司网站
  • 化妆品网站的建设方案建设部精神文明建设网站