我是springMVC的新手,今天我写了一个这样的DateConverter
public class DateConverter implements Converter<String,Date>{
private String formatStr = "";
public DateConverter(String fomatStr) {
this.formatStr = formatStr;
}
public Date convert(String source) {
SimpleDateFormat sdf = null;
Date date = null;
try {
sdf = new SimpleDateFormat(formatStr);
date = sdf.parse(source);
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
}
然后我写一个这样的控制器
@RequestMapping(value="/converterTest")
public void testConverter(Date date){
System.out.println(date);
}
将其配置为 applicationContext,我确信 DateConverter 已正确初始化,当我测试我的转换器时
http://localhost:8080/petStore/converterTest?date=2011-02-22
the browser says:
HTTP Status 400 -
type Status report
message
description The request sent by the client was syntactically incorrect ().
有人可以帮我吗?提前致谢