In this tutorial you will see an example of a Spring Date Editor.
In this tutorial you will see an example of a Spring Date Editor.Passing a date format in the bean property is not allowed and in order to do so you need to declare a CustomDateEditor class for converting the String into java.util.Date properties.
Employee.java
package spring.date.property;
import java.util.Date;
public class Employee {
private Date joiningDate;
private String name;
public Date getJoiningDate() {
return joiningDate;
}
public void setJoiningDate(Date joiningDate) {
this.joiningDate = joiningDate;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
AppMain.java
package spring.date.property;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class AppMain {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext(
new String[] { "context.xml" });
Employee emp = (Employee) context.getBean("bean1");
System.out.println(emp.getJoiningDate());
}
}
context.xml
<?xml version="1.0" encoding="UTF-8"?>
|
| Wed Sep 01 00:00:00 GMT+05:30 2010 |