diff --git a/flowers-SpringProject/src/bean-ioc.xml b/flowers-SpringProject/src/bean-ioc.xml index db593c8..b86fcd1 100644 --- a/flowers-SpringProject/src/bean-ioc.xml +++ b/flowers-SpringProject/src/bean-ioc.xml @@ -29,5 +29,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/flowers-SpringProject/src/com/ssm/ioc/Announcement.java b/flowers-SpringProject/src/com/ssm/ioc/Announcement.java new file mode 100644 index 0000000..793e9c5 --- /dev/null +++ b/flowers-SpringProject/src/com/ssm/ioc/Announcement.java @@ -0,0 +1,101 @@ +package com.ssm.ioc; + +public class Announcement { + // 公告ID(主键) + private Integer id; + // 公告标题 + private String title; + // 公告内容 + private String content; + // 发布人 + private String publisher; + // 发布时间 + private String publishTime; + // 公告状态(0:未发布 1:已发布) + private Integer status; + + // 无参构造(Spring IoC 必须) + public Announcement() { + } + + // 全参构造(可选,方便初始化) + public Announcement(Integer id, String title, String content, String publisher, String publishTime, Integer status) { + this.id = id; + this.title = title; + this.content = content; + this.publisher = publisher; + this.publishTime = publishTime; + this.status = status; + } + + // Getter & Setter(Spring 依赖注入必须) + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + 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; + } + + public Integer getStatus() { + return status; + } + + public void setStatus(Integer status) { + this.status = status; + } + + public void printInfo() { + System.out.println("===== 公告信息 ====="); + System.out.println("公告ID:" + id); + System.out.println("公告标题:" + title); + System.out.println("公告内容:" + content); + System.out.println("发布人:" + publisher); + System.out.println("发布时间:" + publishTime); + System.out.println("公告状态:" + (status == 1 ? "已发布" : "未发布")); + } + + @Override + public String toString() { + return "Announcement{" + + "id=" + id + + ", title='" + title + '\'' + + ", content='" + content + '\'' + + ", publisher='" + publisher + '\'' + + ", publishTime='" + publishTime + '\'' + + ", status=" + status + + '}'; + } +} \ No newline at end of file diff --git a/flowers-SpringProject/src/com/ssm/ioc/Testioc.java b/flowers-SpringProject/src/com/ssm/ioc/Testioc.java index a497ff3..8944ec1 100644 --- a/flowers-SpringProject/src/com/ssm/ioc/Testioc.java +++ b/flowers-SpringProject/src/com/ssm/ioc/Testioc.java @@ -22,6 +22,10 @@ public class Testioc { Message message = context.getBean("message", Message.class); System.out.println("留言信息:" + message); + Announcement announcement = context.getBean("announcement", Announcement.class); + //直接打印对象 + System.out.println("公告信息:" + announcement); + } diff --git a/out/production/flowers-SpringProject/bean-ioc.xml b/out/production/flowers-SpringProject/bean-ioc.xml index db593c8..b86fcd1 100644 --- a/out/production/flowers-SpringProject/bean-ioc.xml +++ b/out/production/flowers-SpringProject/bean-ioc.xml @@ -29,5 +29,14 @@ + + + + + + + + + \ No newline at end of file diff --git a/out/production/flowers-SpringProject/com/ssm/ioc/Testioc.class b/out/production/flowers-SpringProject/com/ssm/ioc/Testioc.class index 7099da5..ea017eb 100644 Binary files a/out/production/flowers-SpringProject/com/ssm/ioc/Testioc.class and b/out/production/flowers-SpringProject/com/ssm/ioc/Testioc.class differ