『 날짜형 바인드 컨트롤러 작성 』

​<컨트롤러 작성>

​ @RequestMapping(method=RequestMethod.GET)
    public void setupForm(Model model) {
        CustomizeDateBindCommand command = createInitCommand();
        // 시작일자 초기값은 현재일자
        command.setStartDate(new Date());        
        model.addAttribute("command", command);
    }
   
    @RequestMapping(method=RequestMethod.POST)
    public ModelAndView doAction1(@ModelAttribute("command") CustomizeDateBindCommand command,
            BindingResult bindingResult) {
       
        System.out.println(command.toString());
       
        // 바인드 에러 처리
        if(bindingResult.hasErrors()) {
            ModelAndView mav = new ModelAndView();
            mav.getModel().putAll(bindingResult.getModel());
            return mav;
        }
       
        ModelAndView mav = new ModelAndView("forward:/hello.html");
        return mav;
    }


 

 

 

 

 

+ Recent posts