创建了TestIoc.xml和bean-ioc.xml,创建了Order.java实现了订单管理模块

main
niu123456789101112 3 days ago
parent 28c2c85261
commit ed15c347a4

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<bean id="order" class="com.ssm.ioc.Order">
<property name="id" value="ORD20260410001"/>
<property name="username" value="zhangsan"/>
<property name="flowerName" value="郁金香"/>
<property name="nums" value="2"/>
<property name="orderDate" value="2026-04-10 15:00:00"/>
<property name="totalPrice" value="99.8"/>
</bean>
</beans>

@ -0,0 +1,56 @@
package com.ssm.ioc;
import java.util.Date;
/**
*
* 4
*/
public class Order {
// 订单编号
private String id;
// 下单人用户名(关联用户)
private String username;
// 花卉名称(关联花卉)
private String flowerName;
// 购买数量
private Integer nums;
// 下单日期
private Date orderDate;
// 订单总金额
private Double totalPrice;
// 【必须】无参构造器Spring IoC强制要求
public Order() {}
// 【必须】完整Getter/Setter
public String getId() { return id; }
public void setId(String id) { this.id = id; }
public String getUsername() { return username; }
public void setUsername(String username) { this.username = username; }
public String getFlowerName() { return flowerName; }
public void setFlowerName(String flowerName) { this.flowerName = flowerName; }
public Integer getNums() { return nums; }
public void setNums(Integer nums) { this.nums = nums; }
public Date getOrderDate() { return orderDate; }
public void setOrderDate(Date orderDate) { this.orderDate = orderDate; }
public Double getTotalPrice() { return totalPrice; }
public void setTotalPrice(Double totalPrice) { this.totalPrice = totalPrice; }
@Override
public String toString() {
return "Order{" +
"id='" + id + '\'' +
", username='" + username + '\'' +
", flowerName='" + flowerName + '\'' +
", nums=" + nums +
", orderDate=" + orderDate +
", totalPrice=" + totalPrice +
'}';
}
}

@ -0,0 +1,26 @@
package com.ssm.ioc;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
/**
* Spring IoC
*
*/
public class TestIoc {
public static void main(String[] args) {
// 1. 加载Spring配置文件
ApplicationContext context = new ClassPathXmlApplicationContext("bean-ioc.xml");
// ========== 5. 订单管理模块 ==========
System.out.println("===== 5. 订单管理模块信息 =====");
Order order = context.getBean("order", Order.class);
System.out.println("订单编号:" + order.getId());
System.out.println("下单人:" + order.getUsername());
System.out.println("花卉名称:" + order.getFlowerName());
System.out.println("购买数量:" + order.getNums());
System.out.println("下单日期:" + order.getOrderDate());
System.out.println("订单总金额:" + order.getTotalPrice());
System.out.println("完整订单信息:" + order + "\n");
}
}
Loading…
Cancel
Save