<tr class="rowsAdded">
<td><input name="item" class="form-control" type="text" placeholder="Item" /></td>
<td><input name="amount" class="form-control" type="number" placeholder="Amount" /></td>
<td><input name="expenseDate" class="form-control" type="date"placeholder="ExpenseDate" /></td>
</tr>
以下是我的控制器和初始化绑定器:
@RequestMapping (value = "/saveExpenses", method=RequestMethod.POST)
public String saveExpenses (@RequestBody ExpenseDetailsListVO expenseDetailsListVO, Model model,BindingResult result) {
if (result.hasErrors()) {
System.out.println(result.getFieldError().getField().toString()+" error");
}
System.out.println(expenseDetailsListVO);
return "success";
}
@InitBinder
public void initBinder(WebDataBinder webDataBinder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
webDataBinder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}
这种方式我想要的日期格式不起作用,这是我得到的输出结果: expenseDate=Wed Mar 18 05:30:00 IST 2015 但我想要它按照特定的格式如yyyy-MM-dd来显示...请建议一种方法。
dateFormat.format(yourDateObj)
。 - Abhishek Nayak