完成订单管理注解

main
niu123456789101112 3 days ago
parent ca48c01745
commit d6a1cd78ca

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

@ -0,0 +1,65 @@
package com.ssm.di.annotation;
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 void setOrderDateStr(String dateStr) {
try {
java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
this.orderDate = sdf.parse(dateStr);
} catch (Exception e) {
e.printStackTrace();
}
}
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,13 @@
package com.ssm.di.annotation;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestDI {
public static void main(String[] args){
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-annotation.xml");
Order order = (Order) ac.getBean("order");
System.out.println("===== 订单管理 =====");
System.out.println(order);
}
}
Loading…
Cancel
Save