From 47d346da294e5bbf491fb5c4eaae4ceeda9d52c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=B4=E7=9D=BF=E8=AF=97?= Date: Mon, 13 Apr 2026 17:24:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9F=BA=E4=BA=8E=E5=B1=9E=E6=80=A7=E6=B3=A8?= =?UTF-8?q?=E5=85=A5=EF=BC=8C=E4=BF=AE=E6=94=B9=E4=B8=BA=E6=9E=84=E9=80=A0?= =?UTF-8?q?=E6=B3=A8=E5=85=A5=EF=BC=8C=E6=96=B0=E5=BB=BAconstructor?= =?UTF-8?q?=E5=8C=85=E4=BB=A5=E5=8F=8Abean-di-constructor.xml=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=EF=BC=8C=E4=BF=AE=E6=94=B9=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=96=87=E4=BB=B6=E5=86=85=E5=AE=B9=E4=B8=BA=E6=9E=84?= =?UTF-8?q?=E9=80=A0=E6=B3=A8=E5=85=A5=EF=BC=8C=E6=96=B0=E5=A2=9EBudget?= =?UTF-8?q?=E5=AE=9E=E4=BD=93=E7=B1=BB=E7=9A=84=E6=97=A0=E5=8F=82=E5=8F=8A?= =?UTF-8?q?=E5=85=A8=E5=8F=82=E6=9E=84=E9=80=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/bean-di-constructor.xml | 17 ++++ .../src/com/ssm/di/constructor/Budget.java | 87 +++++++++++++++++++ .../src/com/ssm/di/constructor/TestDI.java | 18 ++++ .../src/com/ssm/di/constructor/TestNew.java | 20 +++++ 4 files changed, 142 insertions(+) create mode 100644 ffms-SpringProject/src/bean-di-constructor.xml create mode 100644 ffms-SpringProject/src/com/ssm/di/constructor/Budget.java create mode 100644 ffms-SpringProject/src/com/ssm/di/constructor/TestDI.java create mode 100644 ffms-SpringProject/src/com/ssm/di/constructor/TestNew.java diff --git a/ffms-SpringProject/src/bean-di-constructor.xml b/ffms-SpringProject/src/bean-di-constructor.xml new file mode 100644 index 0000000..2a7e162 --- /dev/null +++ b/ffms-SpringProject/src/bean-di-constructor.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/ffms-SpringProject/src/com/ssm/di/constructor/Budget.java b/ffms-SpringProject/src/com/ssm/di/constructor/Budget.java new file mode 100644 index 0000000..3d9ba70 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/constructor/Budget.java @@ -0,0 +1,87 @@ +package com.ssm.di.constructor; + +import java.math.BigDecimal; + + +public class Budget { + //预算编号 + private Integer budgetId; + //预算分类 + private String category; + //预算金额 + private BigDecimal amount; + //预算周期 + private String period; + //预算生效日期 + private String startDate; + //预算备注 + private String remark; + + public Budget(){} + + public Budget(Integer budgetId, String category, BigDecimal amount, String period, String startDate, String remark) { + this.budgetId = budgetId; + this.category = category; + this.amount = amount; + this.period = period; + this.startDate = startDate; + this.remark = remark; + } + + public Integer getBudgetId() { + return budgetId; + } + + public void setBudgetId(Integer budgetId) { + this.budgetId = budgetId; + } + + public String getCategory() { + return category; + } + + public void setCategory(String category) { + this.category = category; + } + + public BigDecimal getAmount() { + return amount; + } + + public void setAmount(BigDecimal amount) { + this.amount = amount; + } + + public String getPeriod() { + return period; + } + + public void setPeriod(String period) { + this.period = period; + } + + public String getStartDate() { + return startDate; + } + + public void setStartDate(String startDate) { + this.startDate = startDate; + } + + public String getRemark() { + return remark; + } + + public void setRemark(String remark) { + this.remark = remark; + } + //自定义方法 + public String toString(){ + return "预算编号:" + budgetId + "\n" + + "预算分类:" + category +"\n" + + "预算金额:" + amount + "\n" + + "预算周期:" + period + "\n" + + "生效日期:" + startDate + "\n" + + "备注:" + remark; + } +} diff --git a/ffms-SpringProject/src/com/ssm/di/constructor/TestDI.java b/ffms-SpringProject/src/com/ssm/di/constructor/TestDI.java new file mode 100644 index 0000000..e29d346 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/constructor/TestDI.java @@ -0,0 +1,18 @@ +package com.ssm.di.constructor; + + +import org.springframework.context.ApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +public class TestDI { +public static void main(String[] args) { + //1.初始化Spring容器,加载配置文件 + ApplicationContext applicationContext = new ClassPathXmlApplicationContext("bean-di-constructor.xml"); + + //获得Budget对象 + Budget budget = (Budget) applicationContext.getBean("budget"); + //输出Budget实例的信息 + System.out.println(budget.toString()); + +} +} diff --git a/ffms-SpringProject/src/com/ssm/di/constructor/TestNew.java b/ffms-SpringProject/src/com/ssm/di/constructor/TestNew.java new file mode 100644 index 0000000..a3a58b5 --- /dev/null +++ b/ffms-SpringProject/src/com/ssm/di/constructor/TestNew.java @@ -0,0 +1,20 @@ +package com.ssm.di.constructor; + +import java.math.BigDecimal; + +public class TestNew { +public static void main(String[] args) { + //通过new的方式实例化Budget对象 + Budget budget = new Budget(); + budget.setBudgetId(0001); + budget.setCategory("餐饮预算"); + budget.setAmount(new BigDecimal("5000.00")); + budget.setPeriod("月度"); + budget.setStartDate("2025-04-13"); + budget.setRemark("无"); + System.out.println(budget); + + +} +} +