๐ŸŒฑ Spring์—์„œ request ์ฒ˜๋ฆฌ ๊ณผ์ •


Spring์—์„œ request ์ฒ˜๋ฆฌ ๊ณผ์ •

  • DispatcherServlet : ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ „๋‹ฌ ๋ฐ›์•„ ์š”์ฒญ์— ๋งž๋Š” ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ๋ฐ˜ํ™˜ํ•œ ๊ฒฐ๊ณผ๊ฐ’์„ View์— ์ „๋‹ฌํ•˜์—ฌ ์•Œ๋งž์€ ์‘๋‹ต ์ƒ์„ฑ
  • HandlerMapping : ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ URL์„ ์–ด๋–ค ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์ฒ˜๋ฆฌํ• ์ง€ ๊ฒฐ์ •
  • Controller : ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•œ ๋’ค, ๊ฒฐ๊ณผ๋ฅผ DispatcherServlet์— ๋ฐ˜ํ™˜
  • ModelAndView : ์ปจํŠธ๋กค๋Ÿฌ๊ฐ€ ์ฒ˜๋ฆฌํ•œ ๊ฒฐ๊ณผ ์ •๋ณด ๋ฐ ๋ทฐ ์„ ํƒ์— ํ•„์š”ํ•œ ์ •๋ณด๋ฅผ ๋‹ด์Œ
  • ViewResolver : ์ปจํŠธ๋กค๋Ÿฌ์˜ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ๋ฅผ ์ƒ์„ฑํ•  ๋ทฐ๋ฅผ ๊ฒฐ์ •
  • View : ์ปจํŠธ๋กค๋Ÿฌ์˜ ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ํ™”๋ฉด์„ ์ƒ์„ฑ, JSP ๋˜๋Š” ํ…œํ”Œ๋ฆฟ ์—”์ง„์„ ๋ทฐ๋กœ ์‚ฌ์šฉ
  1. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„์— ์š”์ฒญ์„ ํ•˜๋ฉด DispatcherServlet์ด ์š”์ฒญ์„ ๊ฐ€๋กœ์ฑˆ๋‹ค.
  2. ์š”์ฒญ์„ ๊ฐ€๋กœ์ฑˆ DispatcherServlet์€ HandlerMapping์—๊ฒŒ ์–ด๋–ค ์ปจํŠธ๋กค๋Ÿฌ์—๊ฒŒ ์š”์ฒญ์„ ์œ„์ž„ํ•˜๋ฉด ์ข‹์„์ง€ ๋ฌผ์–ด๋ณธ๋‹ค.
    (HandlerMapping์€ @Controller๋กœ ๋“ฑ๋กํ•œ ๊ฒƒ๋“ค์„ ์Šค์บ”ํ•ด์„œ ์ฐพ์•„ ๋†“์•˜๋‹ค.)
  3. ์š”์ฒญ์— ๋งคํ•‘๋œ Controller๊ฐ€ ์žˆ๋‹ค๋ฉด @RequestMapping์„ ํ†ตํ•˜์—ฌ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ๋ฉ”์„œ๋“œ์— ๋„๋‹ฌํ•œ๋‹ค.
    (์ด๋Š” HandlerAdapter๊ฐ€ ์ฑ…์ž„์ง„๋‹ค.)
  4. Controller์—์„œ๋Š” ํ•ด๋‹น ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  Service์—๊ฒŒ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์œ„์ž„ํ•œ๋‹ค.
  5. Service์—์„œ๋Š” DB ์ ‘๊ทผ์ด ํ•„์š”ํ•  ๊ฒฝ์šฐ DB ์ฒ˜๋ฆฌ๋ฅผ DAO์—๊ฒŒ ์œ„์ž„ํ•œ๋‹ค.
  6. DAO๋Š” ๋ฐ์ดํ„ฐ ์ •๋ณด๋ฅผ ๋ฐ›์•„ Service์—๊ฒŒ ๋Œ๋ ค์ค€๋‹ค.
    (๊ฒฐ๊ณผ๋กœ ๋ฐ›์€ Entity ๊ฐ์ฒด๋ฅผ ๊ฐ€์ง€๊ณ  Response์— ํ•„์š”ํ•œ DTO ๊ฐ์ฒด๋กœ ๋ณ€ํ™˜ํ•œ๋‹ค.)
  7. ๋ชจ๋“  ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๋๋‚ธ Service๊ฐ€ ๊ฒฐ๊ณผ๋ฌผ์„ Controller์— ๋„˜๊ธด๋‹ค.
  8. ๊ฒฐ๊ณผ๋ฌผ์„ ๋ฐ›์€ Controller๋Š” ํ•„์š”์— ๋”ฐ๋ผ Model ๊ฐ์ฒด์— ๊ฒฐ๊ณผ๋ฌผ์„ ๋„ฃ๊ฑฐ๋‚˜, View ์ •๋ณด๋ฅผ ๋‹ด์•„ DispatcherServlet์—๊ฒŒ ๋ณด๋‚ธ๋‹ค.
  9. DispatcherServlet์€ ViewResolver์—๊ฒŒ ๋ฐ›์€ ๋ทฐ์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ๋„˜๊ธด๋‹ค.
  10. ViewResolver๋Š” ํ•ด๋‹น View๋ฅผ ์ฐพ์•„ DispatcherServlet์—๊ฒŒ ์•Œ๋ ค์ค€๋‹ค.
    (serffix, prefix๋ฅผ ๋ถ™์—ฌ์ฃผ๋Š” ๊ฒƒ๋„ ViewResolver์—์„œ ์ˆ˜ํ–‰ํ•œ๋‹ค.)
  11. DispatcherServlet์€ ์‘๋‹ตํ•  View์—๊ฒŒ Render๋ฅผ ์ง€์‹œํ•˜๊ณ  View๋Š” ์‘๋‹ต ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•œ๋‹ค.
  12. DispatcherServlet์ด ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ๋ Œ๋”๋ง๋œ View๋ฅผ ์‘๋‹ตํ•œ๋‹ค.

์ฐธ๊ณ 

Spring MVC ๊ตฌ์กฐ์˜ ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ์„ค๋ช…ํ•ด๋ณด์‹œ์˜ค. (MVC process)