From 34be2fe4ad78faeddd439c830037b2aba44ffcea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?2506980119=E5=91=A8=E4=BA=91=E7=92=81?= <3199457464@qq.com> Date: Tue, 14 Apr 2026 15:39:32 +0800 Subject: [PATCH] =?UTF-8?q?=3D=3D=3D=3D=3D=20=E5=95=86=E5=93=81=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=20=3D=3D=3D=3D=3D=20Product{pid=3D1,=20pname=3D'?= =?UTF-8?q?=E9=9D=92=E7=9A=AE=E9=A6=99=E7=8E=89=E8=8A=92=E6=9E=9C',=20mark?= =?UTF-8?q?etPrice=3D20.0,=20shopPrice=3D20.0,=20image=3D'products/c185f59?= =?UTF-8?q?7-c2f7-48b7-xxxx'}?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ===== 分类信息 ===== Category{cid=101, cname='生鲜水果', description='新鲜应季水果,产地直供'} --- .../com.ssm.di.xml/bean-di-xml.xml | 23 ++++++++++++ .../com/ssm/di/xml/Category.java | 27 ++++++++++++++ .../com/ssm/di/xml/Product.java | 37 +++++++++++++++++++ .../com.ssm.di.xml/com/ssm/di/xml/TestDI.java | 21 +++++++++++ 4 files changed, 108 insertions(+) create mode 100644 equipment-SpringProject/com.ssm.di.xml/bean-di-xml.xml create mode 100644 equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Category.java create mode 100644 equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Product.java create mode 100644 equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/TestDI.java diff --git a/equipment-SpringProject/com.ssm.di.xml/bean-di-xml.xml b/equipment-SpringProject/com.ssm.di.xml/bean-di-xml.xml new file mode 100644 index 0000000..d3cbe18 --- /dev/null +++ b/equipment-SpringProject/com.ssm.di.xml/bean-di-xml.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Category.java b/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Category.java new file mode 100644 index 0000000..25224b3 --- /dev/null +++ b/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Category.java @@ -0,0 +1,27 @@ +package com.ssm.di.xml; + +public class Category { + private Integer cid; + private String cname; + private String description; + + public Category() {} + + public Integer getCid() { return cid; } + public void setCid(Integer cid) { this.cid = cid; } + + public String getCname() { return cname; } + public void setCname(String cname) { this.cname = cname; } + + public String getDescription() { return description; } + public void setDescription(String description) { this.description = description; } + + @Override + public String toString() { + return "Category{" + + "cid=" + cid + + ", cname='" + cname + '\'' + + ", description='" + description + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Product.java b/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Product.java new file mode 100644 index 0000000..6b9468f --- /dev/null +++ b/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/Product.java @@ -0,0 +1,37 @@ +package com.ssm.di.xml; + +public class Product { + private Integer pid; + private String pname; + private Double marketPrice; + private Double shopPrice; + private String image; + + public Product() {} + + public Integer getPid() { return pid; } + public void setPid(Integer pid) { this.pid = pid; } + + public String getPname() { return pname; } + public void setPname(String pname) { this.pname = pname; } + + public Double getMarketPrice() { return marketPrice; } + public void setMarketPrice(Double marketPrice) { this.marketPrice = marketPrice; } + + public Double getShopPrice() { return shopPrice; } + public void setShopPrice(Double shopPrice) { this.shopPrice = shopPrice; } + + public String getImage() { return image; } + public void setImage(String image) { this.image = image; } + + @Override + public String toString() { + return "Product{" + + "pid=" + pid + + ", pname='" + pname + '\'' + + ", marketPrice=" + marketPrice + + ", shopPrice=" + shopPrice + + ", image='" + image + '\'' + + '}'; + } +} \ No newline at end of file diff --git a/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/TestDI.java b/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/TestDI.java new file mode 100644 index 0000000..5fb6836 --- /dev/null +++ b/equipment-SpringProject/com.ssm.di.xml/com/ssm/di/xml/TestDI.java @@ -0,0 +1,21 @@ +package com.ssm.di.xml; + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class TestDI { + public static void main(String[] args) { + // 1. 加载 src 下的 bean-di-xml.xml + ApplicationContext ac = new ClassPathXmlApplicationContext("bean-di-xml.xml"); + + // 2. 获取 Product 并输出 + Product product = ac.getBean("product", Product.class); + System.out.println("===== 商品信息 ====="); + System.out.println(product); + + // 3. 获取 Category 并输出 + Category category = ac.getBean("category", Category.class); + System.out.println("\n===== 分类信息 ====="); + System.out.println(category); + } +} \ No newline at end of file