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 0000000..3c5cf8b Binary files /dev/null and b/film-SpringProject/src/lib/com.springsource.org.aopalliance-1.0.0.jar differ