redirect ์ ๋ฐ์ดํฐ ์ ๋ฌ ๋ฐฉ๋ฒ
- RedirectAttributes ํด๋์ค๋ฅผ ์ฌ์ฉํ์ฌ ์ ๋ฌ
- RedirectAttributes ํด๋์ค๋ Spring 3.1 ๋ฒ์ ์ ์ถ๊ฐ๋จ
- RedirectAttributes ํด๋์ค๋ฅผ ํตํด String ํํ๋ฅผ ํฌํจํ map, list, vo ๋ฑ์ Object ํํ๋ก ์ ๋ฌ ๊ฐ๋ฅ
๋์ ์ค์ต | addAttribute
message ์ ๋ด์ ๊ฐ์ฒด๋ฅผ redirect ๋ฅผ ํตํด์ ๋ณด๋ด๊ณ ์ ํ๋ ๊ฒฝ๋ก๋ก ๋ฐ์ดํฐ๋ฅผ ๋ณด๋๋ค.
/abc?message=๋ฑ๋ก๋์์ต๋๋ค.
์ํ์ฐฉ์ค | method = RequestMethod.POST
redirect ์ RequestMethod.POST ๋ก ๋ณด๋ด๊ฒ ๋ ๊ฒฝ์ฐ (postman ์ผ๋ก๋ ํ์ธ ๊ฐ๋ฅ)
// WARN : org.springframework.web.servlet.PageNotFound - Request method 'GET' not supported
RequestMethod.GET ์ ์ถ๊ฐํ๊ฑฐ๋ ์ฝ๋์ ๊ฐ์ด ๊ธฐ๋ณธ๊ฐ์ผ๋ก ์ฌ์ฉํ๋ค.
๋์ ์ค์ต | addFlashAttribute
๊ฒ์๊ธ์ ๋ฑ๋ก/์์ /์ญ์ ๋ฑ ๋ณด์์ ๋ฏผ๊ฐํ ๊ธฐ๋ฅ์ ๋ง์ด ์ฌ์ฉ๋จ
ํ๋ฐ์ฑ ๋ฐ์ดํฐ(์๋ก๊ณ ์นจ ์ ๋ฐ์ดํฐ ์ฌ๋ผ์ง)
addAttribute ๋ฅผ ์ฌ์ฉํ์ ๋ GET ์ผ๋ก ๋ฐ์ ๊ฐ์ฒด ๋ฐ์ดํฐ๋ URL ์ ๊ณ ์ค๋ํ ๋จ์์๋ ๋ฐ๋ฉด์
addFlashAttribute ๋ฅผ ์ฌ์ฉํ์ ๋ POST ๋ก ๊ฐ์ฒด๋ฅผ ์ ๋ฌํ์ฌ URL ์๋ ๋
ธ์ถ๋์ง ์๋๋ค.
post url ํํ
๊ทธ๋ ๋ค๋ฉด ๊ฐ์ฒด๋ฅผ ๋ด์ ๋ฐ์ดํฐ๋ ์ด๋ป๊ฒ ํ์ธํ ์ ์๋๊ฐ?
(1) | ModelAttribute
" @ModelAttribute("message") String text "
addAttribute/addFlashAttribute ์ผ๋ก ๊ฐ์ฒด๋ฅผ ๋ณด๋ด๊ณ , ํ๋ผ๋ฏธํฐ Key ๋ฅผ ๋ฐ์ ํ์
์ ๋ง๊ฒ ๊ฐ์ฒด์ ๋ด์์ ์ฌ์ฉํ๋ค.
(2) | RequestContextUtils.getInputFlashMap(request)
RequestContextUtils.getInputFlashMap(request)
์ถ๋ ฅ(print)
// FlashMap [attributes={message=๋ฑ๋ก๋์์ต๋๋ค.}, targetRequestPath=/ch2/bbb, targetRequestParams={}]
(3) | JSP
${ key }
๊ฐ์ฒด ๋ฐ์ดํฐ๋ฅผ ๋ฐ๊ณ ์ ํ๋ ' .jsp ' ์ ${ key } ๋ฅผ ์
๋ ฅํ๋ฉด, addAttribute/addFlashAttribute ์ผ๋ก ๋ณด๋ธ ๊ฐ์ฒด ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์ ์๋ค.
์ถ์ฒ | https://web-obj.tistory.com/455
์ถ์ฒ | https://galid1.tistory.com/563
์ถ์ฒ | https://m.blog.naver.com/allkanet72/220964699929