diff --git a/hospital-SpringProject/hospital-SpringProject.iml b/hospital-SpringProject/hospital-SpringProject.iml index 38a4178..6bf65b7 100644 --- a/hospital-SpringProject/hospital-SpringProject.iml +++ b/hospital-SpringProject/hospital-SpringProject.iml @@ -8,5 +8,6 @@ + \ No newline at end of file diff --git a/hospital-SpringProject/src/bean-aop.xml b/hospital-SpringProject/src/bean-aop.xml new file mode 100644 index 0000000..08acf29 --- /dev/null +++ b/hospital-SpringProject/src/bean-aop.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/hospital-SpringProject/src/com/ssm/aop/Announcement.java b/hospital-SpringProject/src/com/ssm/aop/Announcement.java new file mode 100644 index 0000000..ddc5905 --- /dev/null +++ b/hospital-SpringProject/src/com/ssm/aop/Announcement.java @@ -0,0 +1,7 @@ +package com.ssm.aop; + +public class Announcement { + public void printPub(){ + System.out.println("公告编号:1 公告标题:春节不打烊 公告内容:正常发货 公告时间:2025-01-25"); + } +} \ No newline at end of file diff --git a/hospital-SpringProject/src/com/ssm/aop/Category.java b/hospital-SpringProject/src/com/ssm/aop/Category.java new file mode 100644 index 0000000..d1e8c3c --- /dev/null +++ b/hospital-SpringProject/src/com/ssm/aop/Category.java @@ -0,0 +1,7 @@ +package com.ssm.aop; + +public class Category { + public void printMessage(){ + System.out.println("商品类型:1 商品名称:观花类 商品描述:以观赏花色、花形为主 商品状态:缺货"); + } +} \ No newline at end of file diff --git a/hospital-SpringProject/src/com/ssm/aop/Content.java b/hospital-SpringProject/src/com/ssm/aop/Content.java new file mode 100644 index 0000000..d692855 --- /dev/null +++ b/hospital-SpringProject/src/com/ssm/aop/Content.java @@ -0,0 +1,7 @@ +package com.ssm.aop; + +public class Content { + public void printContent(){ + System.out.println("内容编号:1 内容标题:介绍 内容信息:花卉商城"); + } +} \ No newline at end of file diff --git a/hospital-SpringProject/src/com/ssm/aop/Flower.java b/hospital-SpringProject/src/com/ssm/aop/Flower.java new file mode 100644 index 0000000..784116c --- /dev/null +++ b/hospital-SpringProject/src/com/ssm/aop/Flower.java @@ -0,0 +1,7 @@ +package com.ssm.aop; + +public class Flower { + public void printFlower(){ + System.out.println("花卉编号:1 花卉名称:玫瑰 花卉产地:中国 花卉价格:50.0"); + } +} \ No newline at end of file diff --git a/hospital-SpringProject/src/com/ssm/aop/Log.java b/hospital-SpringProject/src/com/ssm/aop/Log.java new file mode 100644 index 0000000..a73379a --- /dev/null +++ b/hospital-SpringProject/src/com/ssm/aop/Log.java @@ -0,0 +1,12 @@ +package com.ssm.aop; + +import org.aspectj.lang.JoinPoint; + +public class Log { + public void beforeAdvice(JoinPoint joinPoint) { + Object target = joinPoint.getTarget(); + String methodName = joinPoint.getSignature().getName(); + System.out.println("前置通知:模拟日志的记录...目标类是:" + target + + ", 被切入通知的目标方法为:" + methodName); + } +} \ No newline at end of file diff --git a/hospital-SpringProject/src/com/ssm/aop/TestAop.java b/hospital-SpringProject/src/com/ssm/aop/TestAop.java new file mode 100644 index 0000000..2d78ecb --- /dev/null +++ b/hospital-SpringProject/src/com/ssm/aop/TestAop.java @@ -0,0 +1,23 @@ +package com.ssm.aop; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class TestAop { + public static void main(String[] args) { + // 这里必须用我们专门写的 aop 配置文件 + ApplicationContext ac = new ClassPathXmlApplicationContext("bean-aop.xml"); + + Category category = (Category) ac.getBean("category"); + category.printMessage(); + + Flower flower = (Flower) ac.getBean("flower"); + flower.printFlower(); + + Announcement announcement = (Announcement) ac.getBean("announcement"); + announcement.printPub(); + + Content content = (Content) ac.getBean("content"); + content.printContent(); + } +} \ No newline at end of file