タイムスタンプ付きのオブジェクトを送り返すフォームを作成しようとしています。現在、入力形式は である必要がありますyyyy-MM-dd HH:mm:ss
。タイムスタンプを形式で入力したいのですがdd.MM.yyyy HH:mm
、入力形式を変更するにはどうすればよいですか?
オブジェクト クラス:
public class Test {
private Timestamp dateStart;
public Timestamp getDateStart() {
return dateStart;
}
public void setDateStart(Timestamp dateStart) {
this.dateStart = new Timestamp(dateStart.getTime());
}
}
コントローラーメソッド:
@RequestMapping(value="test", method = RequestMethod.POST)
public View newTest(@ModelAttribute("test") Test test, Model model) {
//save the Test object
}
jsp フォーム:
<form:form action="service/test" method="post" modelAttribute="test">
<form:input type="text" path="dateStart" />
</form:form>
フォーマットが正しくない場合、次のエラーが発生します。
Field error in object 'test' on field 'dateStart': rejected value [22.05.2012 14:00]; codes [typeMismatch.test.dateStart,typeMismatch.dateStart,typeMismatch.java.sql.Timestamp,typeMismatch]; arguments [org.springframework.context.support.DefaultMessageSourceResolvable: codes [test.dateStart,dateStart]; arguments []; default message [dateStart]]; default message [Failed to convert property value of type 'java.lang.String' to required type 'java.sql.Timestamp' for property 'dateStart'; nested exception is org.springframework.core.convert.ConversionFailedException: Unable to convert value "22.05.2012 14:00" from type 'java.lang.String' to type 'java.sql.Timestamp'; nested exception is java.lang.IllegalArgumentException: Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]]