spring-core.jar
spring-beans.jar
spring-context.jar
spring-aop.jar
spring-expresion.jar
commons-logging.jar
applicationContext.xml
<?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">
</beans>
package com.yingside.po;
import java.util.Date;
public class Employee {
private int empId;
private String empName;
private String empTel;
private String empEducation;
private Date empBirthday;
public int getEmpId() {
return empId;
}
public void setEmpId(int empId) {
this.empId = empId;
}
public String getEmpName() {
return empName;
}
public void setEmpName(String empName) {
this.empName = empName;
}
public String getEmpTel() {
return empTel;
}
public void setEmpTel(String empTel) {
this.empTel = empTel;
}
public String getEmpEducation() {
return empEducation;
}
public void setEmpEducation(String empEducation) {
this.empEducation = empEducation;
}
public Date getEmpBirthday() {
return empBirthday;
}
public void setEmpBirthday(Date empBirthday) {
this.empBirthday = empBirthday;
}
@Override
public String toString() {
return "Employee{" +
"empId=" + empId +
", empName='" + empName + '\'' +
", empTel='" + empTel + '\'' +
", empEducation='" + empEducation + '\'' +
", empBirthday=" + empBirthday +
'}';
}
}
<!-- Date类型属性的注入 -->
<bean id="dateFormat" class="java.text.SimpleDateFormat">
<constructor-arg value="yyyy-MM-dd"></constructor-arg>
</bean>
<bean name="employee" class="com.yingside.po.Employee">
<property name="empId" value="1"></property>
<property name="empName" value="刘备"></property>
<property name="empTel" value="13312345671"></property>
<property name="empEducation" value="本科"></property>
<property name="empBirthday" value="1999-10-10"></property>
<!--Date类型属性的注入-->
<!-- <property name="empBirthday">-->
<!-- <bean factory-bean="dateFormat" factory-method="parse">-->
<!-- <constructor-arg value="1997-09-01"></constructor-arg>-->
<!-- </bean>-->
<!-- </property>-->
</bean>
public class Test {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");
Employee employee = (Employee)context.getBean("employee");
System.out.println("employee = " + employee);
}
}