0

プロパティとしてBeanDealSheetFormを持つ Beanがあります。OrderDtos には 4 つの日付フィールドがあります。コントローラーのように日付形式をバインドしていました。ここで、日付フィールド形式の 1 つを次のように変更する必要があります。ListOrderDto@InitBinderMM/dd/yyyyMM/dd/yyyy hh:mm:ss

CustomDateEditors2を作成しようとしまし@InitBinderたが、日付形式に変更はありませんでした。誰かが可能な解決策を持っている場合は、私を助けてください。

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";
        }       
    }   }
4

0 に答える 0