===================== 自定义类型转换器_问题 ===================== 如果Spring提供的类型转换器不能满足需要,则可以自己定义类型转换器。 /src/main/java/cn/tedu/injection/User.java: public class User implements Serializable { private int id; private Date birthday; public void setId(int id) { this.id = id; } _____________ v | Date public void setBirthday(Date birthday) { | this.birthday = birthday; | } | | @Override | public String toString() { | return "Person{" + | "name='" + id + '\'' + | ", birthday=" + birthday + | '}'; | } | } | | /src/main/resources/applicationContext.xml: | | | | | |________| String Error creating bean with name 'user' ... Failed to convert property value of type 'java.lang.String' to required type 'java.util.Date' for property 'birthday' ... Spring并没有提供从String类型到Date类型的类型转换器,这就需要自己定义相应的类型转换器。 例程:Injection