1.redirect시에 String(파라미터) 넘기는 방법
String으로 넘길경우에는 별도로 처리하지 않아도, jsp에서 해당 파라미터 값 (param1) 을 바로 사용할 수 있다.
@RequestMapping(value="/test1.do", method = RequestMethod.GET)
public String test1(RedirectAttributes redirect,
@RequestParam(value="param1") String param1) throws Exception {
redirect.addFlashAttribute("param1", param1);
return "redirect:/test2.do";
}
@RequestMapping(value="/test2.do", method = RequestMethod.GET)
public String test2() throws Exception {
return "test2";
}
2.redirect시에 Object(객체) 넘기는 방법
Object로 넘길경우에는 아래와 같이 넘기고 받는다. TestVO는 임의로 생성한 객체이다.
@RequestMapping(value="/test1.do", method = RequestMethod.GET)
public String test1(RedirectAttributes redirect,TestVO vo) throws Exception {
redirect.addFlashAttribute("vo", vo);
return "redirect:/test2.do";
}
@RequestMapping(value="/test2.do", method = RequestMethod.GET)
public String test2(HttpServletRequest request,Model model) throws Exception {
Map<String, ?> flashMap =RequestContextUtils.getInputFlashMap(request);
if(flashMap!=null) {
TestVO vo =(TestVO)flashMap.get("vo");
model.addAttribute("vo", vo);
}
return "test2";
}
'개발 > Spring' 카테고리의 다른 글
[eclipse] 전자정부프레임워크 project clean 및 build시 느릴때 (0) | 2022.03.02 |
---|---|
[spring] Fail to save: an error occurs while saving the package : The part /docProps/core.xml (0) | 2021.10.12 |
[Spring] tomcat 실행시 이벤트 실행하는 방법 (onApplicationEvent) (0) | 2021.06.03 |
[Spring] json 으로 응답시 객체에서 null인 값 제외하기 (0) | 2021.04.19 |
[tomcat] 실서버 ajax, rest api 응답 timeout 30초일 경우 (0) | 2021.04.19 |