From 4b2fa736bc99ae179efb5bfbd82f2bad1fbd5ece Mon Sep 17 00:00:00 2001 From: crush <2825050096@qq.com> Date: Mon, 27 Apr 2026 10:48:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E7=94=B5=E5=BD=B1=E7=AE=A1?= =?UTF-8?q?=E7=90=86=E6=A8=A1=E5=9D=97AOP=E5=89=8D=E7=BD=AE=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=EF=BC=8C=E5=AE=8C=E6=88=90=E5=88=87=E9=9D=A2=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E5=92=8C=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...com_springsource_org_aopalliance_1_0_0.xml | 9 ++ ...ource_org_aspectj_weaver_1_6_8_RELEASE.xml | 9 ++ .idea/libraries/commons_logging_1_1_1__2_.xml | 9 ++ .idea/libraries/spring_aop_5_1_6_RELEASE.xml | 9 ++ .../spring_aspects_5_1_6_RELEASE.xml | 9 ++ .../libraries/spring_beans_5_1_6_RELEASE.xml | 9 ++ .../spring_context_5_1_6_RELEASE.xml | 9 ++ .idea/libraries/spring_core_5_1_6_RELEASE.xml | 9 ++ .../spring_expression_5_1_6_RELEASE.xml | 9 ++ film-SpringProject/film-SpringProject.iml | 9 ++ film-SpringProject/src/aop-config.xml | 29 +++++ .../src/com/ssm/aop/xml/Log.java | 32 ++++++ .../src/com/ssm/aop/xml/Test.java | 24 ++++ .../src/com/ssm/aop/xml/dyguanli.java | 106 ++++++++++++++++++ ...com.springsource.org.aopalliance-1.0.0.jar | Bin 0 -> 4615 bytes 15 files changed, 281 insertions(+) create mode 100644 .idea/libraries/com_springsource_org_aopalliance_1_0_0.xml create mode 100644 .idea/libraries/com_springsource_org_aspectj_weaver_1_6_8_RELEASE.xml create mode 100644 .idea/libraries/commons_logging_1_1_1__2_.xml create mode 100644 .idea/libraries/spring_aop_5_1_6_RELEASE.xml create mode 100644 .idea/libraries/spring_aspects_5_1_6_RELEASE.xml create mode 100644 .idea/libraries/spring_beans_5_1_6_RELEASE.xml create mode 100644 .idea/libraries/spring_context_5_1_6_RELEASE.xml create mode 100644 .idea/libraries/spring_core_5_1_6_RELEASE.xml create mode 100644 .idea/libraries/spring_expression_5_1_6_RELEASE.xml create mode 100644 film-SpringProject/src/aop-config.xml create mode 100644 film-SpringProject/src/com/ssm/aop/xml/Log.java create mode 100644 film-SpringProject/src/com/ssm/aop/xml/Test.java create mode 100644 film-SpringProject/src/com/ssm/aop/xml/dyguanli.java create mode 100644 film-SpringProject/src/lib/com.springsource.org.aopalliance-1.0.0.jar diff --git a/.idea/libraries/com_springsource_org_aopalliance_1_0_0.xml b/.idea/libraries/com_springsource_org_aopalliance_1_0_0.xml new file mode 100644 index 0000000..12e21aa --- /dev/null +++ b/.idea/libraries/com_springsource_org_aopalliance_1_0_0.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/com_springsource_org_aspectj_weaver_1_6_8_RELEASE.xml b/.idea/libraries/com_springsource_org_aspectj_weaver_1_6_8_RELEASE.xml new file mode 100644 index 0000000..47b7379 --- /dev/null +++ b/.idea/libraries/com_springsource_org_aspectj_weaver_1_6_8_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/commons_logging_1_1_1__2_.xml b/.idea/libraries/commons_logging_1_1_1__2_.xml new file mode 100644 index 0000000..4b9e175 --- /dev/null +++ b/.idea/libraries/commons_logging_1_1_1__2_.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spring_aop_5_1_6_RELEASE.xml b/.idea/libraries/spring_aop_5_1_6_RELEASE.xml new file mode 100644 index 0000000..814fcd6 --- /dev/null +++ b/.idea/libraries/spring_aop_5_1_6_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spring_aspects_5_1_6_RELEASE.xml b/.idea/libraries/spring_aspects_5_1_6_RELEASE.xml new file mode 100644 index 0000000..5e93637 --- /dev/null +++ b/.idea/libraries/spring_aspects_5_1_6_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spring_beans_5_1_6_RELEASE.xml b/.idea/libraries/spring_beans_5_1_6_RELEASE.xml new file mode 100644 index 0000000..721a52c --- /dev/null +++ b/.idea/libraries/spring_beans_5_1_6_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spring_context_5_1_6_RELEASE.xml b/.idea/libraries/spring_context_5_1_6_RELEASE.xml new file mode 100644 index 0000000..b5d3238 --- /dev/null +++ b/.idea/libraries/spring_context_5_1_6_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spring_core_5_1_6_RELEASE.xml b/.idea/libraries/spring_core_5_1_6_RELEASE.xml new file mode 100644 index 0000000..1071e11 --- /dev/null +++ b/.idea/libraries/spring_core_5_1_6_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/libraries/spring_expression_5_1_6_RELEASE.xml b/.idea/libraries/spring_expression_5_1_6_RELEASE.xml new file mode 100644 index 0000000..6817fe5 --- /dev/null +++ b/.idea/libraries/spring_expression_5_1_6_RELEASE.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/film-SpringProject/film-SpringProject.iml b/film-SpringProject/film-SpringProject.iml index 3078e4f..87a2c05 100644 --- a/film-SpringProject/film-SpringProject.iml +++ b/film-SpringProject/film-SpringProject.iml @@ -9,5 +9,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/film-SpringProject/src/aop-config.xml b/film-SpringProject/src/aop-config.xml new file mode 100644 index 0000000..fcdfa1b --- /dev/null +++ b/film-SpringProject/src/aop-config.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/film-SpringProject/src/com/ssm/aop/xml/Log.java b/film-SpringProject/src/com/ssm/aop/xml/Log.java new file mode 100644 index 0000000..79081fe --- /dev/null +++ b/film-SpringProject/src/com/ssm/aop/xml/Log.java @@ -0,0 +1,32 @@ +package com.ssm.aop.xml; + +import org.aspectj.lang.JoinPoint; +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.lang.annotation.Before; +import org.springframework.stereotype.Component; + +/** + * 通用日志切面类(小组共用) + * 实现前置通知,在目标方法执行前输出日志 + */ +@Aspect +@Component +public class Log { + + /** + * 前置通知:在目标方法执行前输出日志 + * 拦截com.ssm.aop.xml包下所有实体类的printInfo方法 + */ + @Before("execution(* com.ssm.aop.xml.*.printInfo(..))") + public void beforePrintInfo(JoinPoint joinPoint) { + // 获取目标类名 + String className = joinPoint.getTarget().getClass().getSimpleName(); + // 获取方法名 + String methodName = joinPoint.getSignature().getName(); + + System.out.println("========== [前置通知] =========="); + System.out.println("即将执行方法: " + className + "." + methodName); + System.out.println("时间: " + new java.util.Date()); + System.out.println("================================"); + } +} diff --git a/film-SpringProject/src/com/ssm/aop/xml/Test.java b/film-SpringProject/src/com/ssm/aop/xml/Test.java new file mode 100644 index 0000000..ff8742a --- /dev/null +++ b/film-SpringProject/src/com/ssm/aop/xml/Test.java @@ -0,0 +1,24 @@ +package com.ssm.aop.xml; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * 测试类 - AOP前置通知测试 + * 小组共用的测试文件 + */ +public class Test { + public static void main(String[] args) { + // 1. 初始化Spring容器,加载AOP配置文件 + ApplicationContext context = new ClassPathXmlApplicationContext("aop-config.xml"); + + System.out.println("========== AOP前置通知测试 ==========\n"); + + // 2. 获取电影管理模块的bean并调用printInfo方法 + // 注意:这里会触发AOP前置通知 + dyguanli movie = (dyguanli) context.getBean("dyguanli"); + movie.printInfo(); + + System.out.println("\n========== 测试完成 =========="); + } +} diff --git a/film-SpringProject/src/com/ssm/aop/xml/dyguanli.java b/film-SpringProject/src/com/ssm/aop/xml/dyguanli.java new file mode 100644 index 0000000..be72a73 --- /dev/null +++ b/film-SpringProject/src/com/ssm/aop/xml/dyguanli.java @@ -0,0 +1,106 @@ +package com.ssm.aop.xml; + +/** + * 电影管理模块实体类(AOP方式) + * 定义在com.ssm.aop.xml包下 + */ +public class dyguanli { + // 属性定义 + private String movieName; // 电影名称 + private String director; // 导演 + private String actor; // 主演 + private String releaseDate; // 上映日期 + private Integer duration; // 时长(分钟) + private String genre; // 类型 + + /** + * 无参构造函数 + */ + public dyguanli() { + } + + /** + * 带参构造函数 + */ + public dyguanli(String movieName, String director, String actor, String releaseDate) { + this.movieName = movieName; + this.director = director; + this.actor = actor; + this.releaseDate = releaseDate; + } + + // ==================== Getter 和 Setter 方法 ==================== + public String getMovieName() { + return movieName; + } + + public void setMovieName(String movieName) { + this.movieName = movieName; + } + + public String getDirector() { + return director; + } + + public void setDirector(String director) { + this.director = director; + } + + public String getActor() { + return actor; + } + + public void setActor(String actor) { + this.actor = actor; + } + + public String getReleaseDate() { + return releaseDate; + } + + public void setReleaseDate(String releaseDate) { + this.releaseDate = releaseDate; + } + + public Integer getDuration() { + return duration; + } + + public void setDuration(Integer duration) { + this.duration = duration; + } + + public String getGenre() { + return genre; + } + + public void setGenre(String genre) { + this.genre = genre; + } + + // ==================== 重写toString方法 ==================== + @Override + public String toString() { + return "dyguanli{" + + "movieName='" + movieName + '\'' + + ", director='" + director + '\'' + + ", actor='" + actor + '\'' + + ", releaseDate='" + releaseDate + '\'' + + ", duration=" + duration + + ", genre='" + genre + '\'' + + '}'; + } + + // ==================== 定义printInfo方法 ==================== + // 这个方法将被AOP前置通知拦截 + public void printInfo() { + System.out.println("=== 电影信息 ==="); + System.out.println("电影名称: " + movieName); + System.out.println("导演: " + director); + System.out.println("主演: " + actor); + System.out.println("上映日期: " + releaseDate); + System.out.println("时长: " + duration + " 分钟"); + System.out.println("类型: " + genre); + System.out.println("=================="); + } +} diff --git a/film-SpringProject/src/lib/com.springsource.org.aopalliance-1.0.0.jar b/film-SpringProject/src/lib/com.springsource.org.aopalliance-1.0.0.jar new file mode 100644 index 0000000000000000000000000000000000000000..3c5cf8bfb06083853d88e1605088545e9127a192 GIT binary patch literal 4615 zcma)A2{e>_7azlnvGm$s%Vd{*nIVa%GJi7N_FnDp*CDtJ_h2x2g#;t@-S0!ZUNK|RCxSW+sSuT5mACu7e zfMSHH&}9ErD5~llJMrd~G=TyQoUTRkHdB~)b^TnsQk$CIkl_#Sa!}{O{hN;GIGv%F z^gOeB%srQ7cZ+f;oj}90)HshNtV^I$eOD8mXNl1llPnp;RW8g`r?0^(c4rB1cgxxP zlH=Ndoqv5#D8}T-SniBEugTuG%%a!lf_jl!o$fEXv(1XfJFGJ-mi!{32`YbIc#}|} zgD_==$Sn?*yeEa`3*wauctMNifO(vBX3(d3R$WI^;V~Mes8Gr(U_OVhtj8M`YFhg#s zy?E-_ zQ%eB7^Iwe+x(5WdYoET|>ywG?>1}C1GPfnPFEOrIB_2!BH+5_n8lJrp^0E3DdTnL( z8#E?%A4>o`PhzH;S)tFnxinwz>H(-ifkf8{=#h%Lsl$m%x!G<@*S^2p`Sm~9Y9pxu zUGksbp9B{*n(k0*5qzVmK2$&H5T^W4?2?w+kLgDB3cRa`LA3D9818)p{K8yT3~~En zUpwZkE8~p?QN)jo5dD~eM9;bVnAhpG%x{eJn4ZZB1QHV`nVtwP2Ts{2$xRt@e9yzy z#)e#u4+aTC*v>{Jt8n)W-cl1m-Z20@yl3wCv8LbFKJm-0#+o5Tk350qB)lg3aAi#4~WN7k9Q1tPX!R;-4Fr3x|$br)G;HqX)VqmxqQK< z^JxL$DgvjEvZC8u%AHb@a`g|v0M|4ub0%;CUQ8G#h-E9}H5YCqFFnmtE%bVXh@G8Ro~=qD{i?6EH`tROjIsQy5S06%hIoj+uhje9|ziw)t9Qr7S$hdnrl!QQ~@E?fORH zER7Nz-v9xCG7!DO*|kaGP%y#(9TXGY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