๊ด€๋ฆฌ ๋ฉ”๋‰ด

Coding Planet

Handler Mapping๊ณผ Request Mapping์ด๋ž€? ๋ณธ๋ฌธ

๐ŸŒฑSPRING

Handler Mapping๊ณผ Request Mapping์ด๋ž€?

jhj.sharon 2023. 5. 18. 20:29
๋ฐ˜์‘ํ˜•
HANDLER MAPPING, REQUEST MAPPING ๋ชจ๋‘ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๊ฐœ๋…์ด๋‹ค.
์ด ๋‘ ๊ฐœ๋…์€ Spring MVC์—์„œ ์ฃผ๋กœ ์‚ฌ์šฉ๋˜๋Š” ๊ฐœ๋…์œผ๋กœ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•˜๋Š”๋ฐ ์ค‘์š”ํ•œ ์—ญํ• ์„ ํ•œ๋‹ค. 

 

 

1. Handler Mapping์ด๋ž€?

 

  • Handler Mapping์€ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ํ•ธ๋“ค๋Ÿฌ(Handler)๋ฅผ ๊ฒฐ์ •ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.
  • ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ๋‹ค์–‘ํ•œ ์š”์ฒญ์„ ๋ฐ›๊ฒŒ ๋˜๋Š”๋ฐ, Handler Mapping์€ ์ด๋Ÿฌํ•œ ์š”์ฒญ์— ๋Œ€ํ•ด ์–ด๋–ค ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๊ฐ€ ์ฒ˜๋ฆฌํ•ด์•ผํ•˜๋Š”์ง€๋ฅผ ๊ฒฐ์ •ํ•œ๋‹ค.
  • ํ•ธ๋“ค๋Ÿฌ ๋งคํ•‘์€ ์š”์ฒญ URL, ์š”์ฒญ ๋ฉ”์„œ๋“œ, ์š”์ฒญ ํ—ค๋” ๋“ฑ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ์ ์ ˆํ•œ ํ•ธ๋“ค๋Ÿฌ๋ฅผ ์„ ํƒํ•˜๊ณ  ๋งคํ•‘ํ•œ๋‹ค.
  • Spring ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ๋Š” 'HandlerMapping' ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•˜์—ฌ ํ•ธ๋“ค๋Ÿฌ ๋งคํ•‘์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. 
  • DispatcherServlet์€ ๋“ฑ๋ก๋œ Handler Mapping์„ ์ฐธ์กฐํ•˜์—ฌ ์š”์ฒญ์„ ์ ์ ˆํ•œ ์ปจํŠธ๋กค๋Ÿฌ๋กœ ์ „๋‹ฌํ•œ๋‹ค.

 

Spring MVC ์š”์ฒญ ์ฒ˜๋ฆฌ ๊ณผ์ •

 

 

 

 

2. Request Mapping

 

  • Request Mapping์€ ์š”์ฒญ URL๊ณผ ํ•ด๋‹น URL์„ ์ฒ˜๋ฆฌํ•˜๋Š” ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๋ฅผ ๋งคํ•‘ํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.
  • ์š”์ฒญ URL์ด ์–ด๋–ค ํ•ด๋“ค๋Ÿฌ์— ์˜ํ•ด ์ฒ˜๋ฆฌ๋˜์–ด์•ผ ํ•˜๋Š”์ง€๋ฅผ ์ง€์ •ํ•œ๋‹ค
  • Request Mapping์€ ์ฃผ๋กœ ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ฉ”์„œ๋“œ์— ์ ์šฉ๋˜๋ฉฐ, ์–ด๋–ค  URL ํŒจํ„ด์— ํ•ด๋‹นํ•˜๋Š” ์š”์ฒญ์ด ํŠน์ • ๋ฉ”์„œ๋“œ๋กœ ๋งคํ•‘๋˜๋„๋ก ์„ค์ •ํ•œ๋‹ค.
  • Spring ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ๋Š” @RequestMapping ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์š”์ฒญ URL๊ณผ ํ•ธ๋“ค๋Ÿฌ ๋ฉ”์„œ๋“œ๋ฅผ ๋งคํ•‘ํ•  ์ˆ˜ ์žˆ๋‹ค. ์ด ์–ด๋…ธํ…Œ์ด์…˜์„ ์ปจํŠธ๋กค๋Ÿฌ ํด๋ž˜์Šค ๋ ˆ๋ฒจ์— ์ ์šฉํ•˜๋ฉด ํ•ด๋‹น ์ปจํŠธ๋กค๋Ÿฌ์˜ ๋ชจ๋“  ๋ฉ”์„œ๋“œ์— ์ ์šฉ๋˜๋ฉฐ, ๋ฉ”์„œ๋“œ ๋ ˆ๋ฒจ์— ์ ์šฉํ•˜๋ฉด ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋งŒ ํŠน์ • URL์— ๋งคํ•‘๋œ๋‹ค. 

 

 

 

 

 

** ์ฆ‰, Handler Mapping์€ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  ํ•ธ๋“ค๋Ÿฌ๋ฅผ ๊ฒฐ์ •ํ•˜๊ณ , Request Mapping์€ ์š”์ฒญ URL๊ณผ ํ•ธ๋“ค๋Ÿฌ(์ปจํŠธ๋กค๋Ÿฌ)๋ฅผ ๋งคํ•‘ํ•˜์—ฌ ์ ์ ˆํ•œ ํ•ธ๋“ค๋Ÿฌ์—๊ฒŒ ์š”์ฒญ์„ ์ „๋‹ฌํ•˜๋Š” ์—ญํ• ์„ ํ•œ๋‹ค.

 

๋ฐ˜์‘ํ˜•
Comments