私は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 ().
誰かが私を助けてくれますか?前もって感謝します