我有 Bean DealSheetForm
,它的属性List
是bean。OrderDto
OrderDtos 有 4 个日期字段。我曾经在控制器@InitBinder
上绑定日期格式。MM/dd/yyyy
现在我需要将日期字段格式之一修改为MM/dd/yyyy hh:mm:ss
我尝试在其中创建 2 CustomDateEditors
,@InitBinder
但在 dateformat 上没有任何变化。如果有人有可能的解决方案,请帮助我。
这是包含 OrdersDto Bean 的 DealSheetBean:
public class DealSheetForm {
private CustomerDto customer=new CustomerDto();
private AutoPopulatingList<OrdersDto> orders =new
AutoPopulatingList<OrdersDto>(OrdersDto.class);
public AutoPopulatingList<OrdersDto> getOrders() {
return orders;
}
public void setOrders(AutoPopulatingList<OrdersDto> orders) {
this.orders = orders;
}
public CustomerDto getCustomer() {
return customer;
}
public void setCustomer(CustomerDto customer) {
this.customer = customer;
}
}
这是我的控制器
@Controller
public class DealSheetController{
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
SimpleDateFormat dateTimeFormat = new SimpleDateFormat("MM/dd/yyyy
HH:mm:ss");
dateFormat.setLenient(false);
dateTimeFormat.setLenient(false);
binder.registerCustomEditor(Date.class,new CustomDateEditor(dateFormat,
true));
binder.registerCustomEditor(Date.class,"orderDate",new
CustomDateEditor(dateTimeFormat, true));
}
@RequestMapping(value="/agent/dealsheet.do",method=RequestMethod.POST)
@ResponseBody
public String saveDealSheets(@ModelAttribute("dealSheet") DealSheetForm
dealSheet,Map<String,Object> map,HttpServletRequest
request,HttpServletResponse response){
try{
log.info("inside saveDealSheeeeeets()");
Authentication
auth=SecurityContextHolder.getContext().getAuthentication();
String user=auth.getName();
HoveyUserDto userDto=this.userService.getUserByUsername(user);
String agentNumber=userDto.getAgentNumber();
this.dealSheetService.saveDealSheetToDB(dealSheet,agentNumber);
String message="Orders Saved Successfully";
map.put("message", message);
return "success";
}
catch(Exception e){
log.error(e.getStackTrace().toString());
return "error";
}
} }