diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/grademanagement-SpringProject/src/bean-di-annotation.xml b/grademanagement-SpringProject/src/bean-di-annotation.xml index 9d4582d..06075c4 100644 --- a/grademanagement-SpringProject/src/bean-di-annotation.xml +++ b/grademanagement-SpringProject/src/bean-di-annotation.xml @@ -10,7 +10,19 @@ - + + + + + + diff --git a/grademanagement-SpringProject/src/com/ssm/di/annotation/Announcement.java b/grademanagement-SpringProject/src/com/ssm/di/annotation/Announcement.java new file mode 100644 index 0000000..315129e --- /dev/null +++ b/grademanagement-SpringProject/src/com/ssm/di/annotation/Announcement.java @@ -0,0 +1,47 @@ +package com.ssm.di.annotation; + +import org.springframework.stereotype.Component; + +@Component("announcement") +public class Announcement { + private String title; + private String content; + private String publisher; + private String publishTime; // 新增:发布时间 + + // 无参构造(Spring 默认需要) + public Announcement() {} + + // getter 和 setter + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getContent() { + return content; + } + + public void setContent(String content) { + this.content = content; + } + + public String getPublisher() { + return publisher; + } + + public void setPublisher(String publisher) { + this.publisher = publisher; + } + + public String getPublishTime() { + return publishTime; + } + + public void setPublishTime(String publishTime) { + this.publishTime = publishTime; + } +} \ No newline at end of file diff --git a/grademanagement-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java b/grademanagement-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java index bad9683..acb7e38 100644 --- a/grademanagement-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java +++ b/grademanagement-SpringProject/src/com/ssm/di/annotation/TestAnnotation.java @@ -24,6 +24,19 @@ public class TestAnnotation { // 4. 测试 toString() 方法输出 System.out.println("=== 调用 toString() 方法输出 ==="); System.out.println(department); + // 加载 Spring 配置文件(确保 xml 中有 ) + ApplicationContext ac = new ClassPathXmlApplicationContext("xml/bean-di-annotation.xml"); + + // 获取公告栏 Bean + Announcement announcement = (Announcement) ac.getBean("announcement"); + + // 输出信息(可先手动赋值测试) + announcement.setTitle("系统维护通知"); + announcement.setContent("系统将于今晚22:00进行维护,请提前保存数据。"); + announcement.setPublisher("管理员"); + announcement.setPublishTime("2025-04-05 10:00:00"); + + System.out.println(announcement.toString()); } diff --git a/out/production/grademanagement-SpringProject/bean-di.xml b/out/production/grademanagement-SpringProject/bean-di.xml index e0179f5..68dc884 100644 --- a/out/production/grademanagement-SpringProject/bean-di.xml +++ b/out/production/grademanagement-SpringProject/bean-di.xml @@ -5,7 +5,7 @@ http://www.springframework.org/schema/beans/spring-beans.xsd"> - +