[英]How to bind date and time separately?
I want to bind date and time separately in a controller. 我想在控制器中分别绑定日期和时间。 I have 1 timepicker and 1 datepicker on a form, i use InitBinder binder for time picker which is, 我在表单上有1个timepicker和1个datepicker,我将InitBinder绑定程序用于时间选择器,即
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setLenient(true);
binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}
But this doesn't work for both time picker and date picker. 但这对于时间选择器和日期选择器均不起作用。 any better suggestion please.... 请任何更好的建议。
Try this with your code: 尝试使用您的代码:
@InitBinder
void allowFields(WebDataBinder webDataBinder){
webDataBinder.setAllowedFields("date");
webDataBinder.setAllowedFields("time");
}
and use this in your POJO: 并在您的POJO中使用它:
@DateTimeFormat(iso = DateTimeFormat.ISO.DATE_TIME)
private Date date;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.