![](/img/trans.png)
[英]Failed to convert property value of type java.lang.String to required type java.util.Date
[英]Failed to convert property value of type java.lang.String to required type java.util.Date for property fromDate;
我需要以這種格式(dd / mm / yyyy)保存日期類型,當前此格式對我有用(mm / dd / yyyy)
我的jsp代碼
<form:input path="fromDate" id="fromDate" />
<form:errors path="fromDate"/>
我使用日期格式的腳本為“格式:'dd / mm / yyyy'”
調節器
public ModelAndView saveOrUpdateAcademic(Academic academic,final BindingResult errors) {
String string = request.getParameter("fromDate");
System.out.println("========="+string+"=========");
try {
if (validator != null) {
validator.validate(academic, errors);
if(errors.hasErrors()){
saveError(request, getText("academic.error",academic.getAcademicYear(),locale));
return new ModelAndView("admin/academicForm", model);
}
}
}
該字符串將正確的格式打印為(“ dd / mm / yyyy)
錯誤:
Failed to convert property value of type java.lang.String to required type java.util.Date for property fromDate; nested exception is java.lang.IllegalArgumentException: Could not parse date: Unparseable date: "26/01/2015"
請幫忙。
在Controller的 initBinder
方法中使用DateFormatter
:
@InitBinder
public void initBinder(WebDataBinder binder) {
binder.addCustomFormatter(new DateFormatter("dd/MM/yyyy","academic.fromDate" ));
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.