我有Bean DealSheetForm
,其中有List
个OrderDto
个bean作为其属性。
OrderDtos有4个日期字段。我使用@InitBinder
将日期格式绑定为控制器上的MM/dd/yyyy
。现在我需要将其中一个日期字段格式修改为MM/dd/yyyy hh:mm:ss
我尝试在CustomDateEditors
中创建2 @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";
}
} }