구조

    @RequestMapping("/calendar")
    public ModelAndView calendar(@RequestParam @Nullable Map<String, String> param){

        System.out.println("param - Calendar");
        System.out.println(param);

        if(param == null){
            System.out.println("first calendar");
            ModelAndView modelAndView = new ModelAndView("calendar");
            return modelAndView;
        }else{
            System.out.println("Got the param");
            System.out.println(param);
            String selectedDate = param.get("selectedDate");
            System.out.println(selectedDate);
            List<Todo> result = calendarService.getTodoList(selectedDate);

            System.out.println(result);

            ModelAndView modelAndView = new ModelAndView("calendar");
            modelAndView.addObject("todo", result);

            System.out.println("Send the result");

            return modelAndView;
        }
    }

    @Transactional
    @RequestMapping(value="/readCalendar", produces="text/html;charset=UTF-8", method = RequestMethod.POST)
    @ResponseBody
    public String readCalendar(@RequestParam Map<String, String> param, RedirectAttributes re) throws ParseException {

        //String selectedDate = param.get("selectedDate");
        System.out.println("param - readCalendar");
        System.out.println(param);
        
        re.addAttribute("param", param.get("selectedDate"));
        System.out.println(re);
        
        //여기서부터 안됨
        return "redirect:/calendar";
    }

RedirectAttribute 리다이렉트시 전달할 파라미터


addAttribute

전달한 값이 url 뒤에 붙으며 리프레시 해도 데이터가 유지됨(Get방식)

addFlashAttribute

전달한 값이 url에 붙지않음 리프레시 하면 사라짐(Post방식)


문제점

readCalendar 메소드에서 리다이렉트가 안된다
도대체 왜…?


해결방안

리다이렉트할 메소드 리턴 타입을 RediretAndView로 변경
return new RedirectView("/calendar"); 리턴