๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ

spring43

[Spring] ์š”์ฒญ ๋งคํ•‘ ํ•ธ๋“ค๋Ÿฌ ์–ด๋Žํ„ฐ์˜ ๊ตฌ์กฐ Argument Resolver ์• ๋…ธํ…Œ์ด์…˜ ๊ธฐ๋ฐ˜ ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ์ฒ˜๋ฆฌํ•˜๋Š” RequestMappingHandlerAdapter๋Š” ๋ฐ”๋กœ ์ด ArgumentResolver๋ฅผ ํ˜ธ์ถœํ•ด์„œ ์ปจํŠธ๋กค๋Ÿฌ(ํ•ธ๋“ค๋Ÿฌ)๊ฐ€ ํ•„์š”๋กœ ํ•˜๋Š” ๋‹ค์–‘ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ๊ฐ’(๊ฐ์ฒด)๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. ๊ทธ๋ฆฌ๊ณ  ์ด๋ ‡๊ฒŒ ํŒŒ๋ผ๋ฏธํ„ฐ์˜ ๊ฐ’์ด ๋ชจ๋‘ ์ค€๋น„๋˜๋ฉด ์ปจํŠธ๋กค๋Ÿฌ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด์„œ ๊ฐ’์„ ๋„˜๊ฒจ์ค€๋‹ค. public interface HandlerMethodArgumentResolver { boolean supportsParameter(MethodParameter parameter); @Nullable Object resolveArgument(MethodParameter parameter, @Nullable ModelAndViewContainer mavContainer, Native.. 2023. 8. 8.
[Spring] ์Šคํ”„๋ง MVC ๊ธฐ๋ณธ ๊ธฐ๋Šฅ @RestController @Controller ๋Š” ๋ฐ˜ํ™˜ ๊ฐ’์ด String ์ด๋ฉด ๋ทฐ ์ด๋ฆ„์œผ๋กœ ์ธ์‹๋œ๋‹ค. ๊ทธ๋ž˜์„œ ๋ทฐ๋ฅผ ์ฐพ๊ณ  ๋ทฐ๊ฐ€ ๋žœ๋”๋ง ๋œ๋‹ค. @RestController ๋Š” ๋ฐ˜ํ™˜ ๊ฐ’์œผ๋กœ ๋ทฐ๋ฅผ ์ฐพ๋Š” ๊ฒƒ์ด ์•„๋‹ˆ๋ผ, HTTP ๋ฉ”์‹œ์ง€ ๋ฐ”๋””์— ๋ฐ”๋กœ ์ž…๋ ฅํ•œ๋‹ค. ๋”ฐ๋ผ์„œ ์‹คํ–‰ ๊ฒฐ๊ณผ๋กœ ok ๋ฉ”์„ธ์ง€๋ฅผ ๋ฐ›์„ ์ˆ˜ ์žˆ๋‹ค. @RequestMapping์— method ์†์„ฑ์œผ๋กœ HTTP ๋ฉ”์„œ๋“œ๋ฅผ ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด HTTP ๋ฉ”์„œ๋“œ์™€๋Š” ๋ฌด๊ด€ํ•˜๊ฒŒ ํ˜ธ์ถœ๋œ๋‹ค. /** * method ํŠน์ • HTTP ๋ฉ”์„œ๋“œ ์š”์ฒญ๋งŒ ํ—ˆ์šฉ * GET, HEAD, POST, PUT, PATCH, DELETE */ @RequestMapping(value = "/mapping-get-v1", method = RequestMethod.GET) public String m.. 2023. 8. 7.
[Spring] ์Šคํ”„๋ง MVC ๊ตฌ์กฐ DispatcherServlet ๊ตฌ์กฐ๋ฅผ ์‚ดํŽด๋ณด์ž DispatcherServlet๋„ ๋ถ€๋ชจ ํด๋ž˜์Šค์—์„œ HttpServlet์„ ์ƒ์†๋ฐ›์•„์„œ ์‚ฌ์šฉํ•˜๊ณ , ์„œ๋ธ”๋ฆฟ์œผ๋กœ ๋™์ž‘ํ•œ๋‹ค. DispatcherServlet -> FrameworkServlet -> HttpServleBean -> HttpServlet ์Šคํ”„๋ง ๋ถ€ํŠธ๋Š” DispathcherServlet์„ ์„œ๋ธ”๋ฆฟ์œผ๋กœ ์ž๋™ ๋“ฑ๋กํ•˜๋ฉด์„œ ๋ชจ๋“  ๊ฒฝ๋กœ๋ฅผ "/"์— ๋Œ€ํ•ด์„œ ๋งคํ•‘ํ•œ๋‹ค. ํ•˜์ง€๋งŒ ๋” ์ž์„ธํ•œ ๊ฒฝ๋กœ์˜ ์šฐ์„ ์ˆœ์œ„๊ฐ€ ๋†’๋‹ค. ์š”์ฒญ ํ๋ฆ„ โœจโœจโœจ ์„œ๋ธ”๋ฆฟ์ด ํ˜ธ์ถœ๋˜๋ฉด Httpservlet์ด ์ œ๊ณตํ•˜๋Š” service()๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค. ์Šคํ”„๋ง MVC๋Š” DispathcerServlet์˜ ๋ถ€๋ชจ์ธ FrameworkServlet์—์„œ service()๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œ ํ•ด๋‘์—ˆ๋‹ค. FrameworkServlet... 2023. 8. 7.
[Spring] ์„œ๋ธ”๋ฆฟ(servlet) aka. MVC ๊ตฌ๋ฒ„์ „ ์„œ๋ธ”๋ฆฟ์€ ์ž๋ฐ” ์–ธ์–ด๋ฅผ ๊ธฐ๋ฐ”๋Šฅ๋กœ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ฐœ๋ฐœํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ๊ธฐ์ˆ ์ด๋‹ค. ์›น ์„œ๋ฒ„์—์„œ ๋™์ž‘ํ•˜๋Š” ์ž๋ฐ” ํด๋ž˜์Šค๋กœ, ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์„ ๋ฐ›์•„ ์ฒ˜๋ฆฌํ•˜๊ณ  ๊ทธ ๊ฒฐ๊ณผ๋ฅผ ๋‹ค์‹œ ํด๋ผ์ด์–ธํŠธ์—๊ฒŒ ์ „์†กํ•˜๋Š” ์—ญํ• ์„ ์ˆ˜ํ–‰ํ•œ๋‹ค. @WebServlet : ์„œ๋ธ”๋ฆฟ ์• ๋…ธํ…Œ์ด์…˜ name : ์„œ๋ธ”๋ฆฟ ์ด๋ฆ„ urlPatterns : URL ๋งคํ•‘ ์˜ˆ ) @WebServlet(name = "helloServlet", urlPatterns = "/hello") HTTP์š”์ฒญ์„ ํ†ตํ•ด ๋งคํ•‘๋œ URL์ด ํ˜ธ์ถœ๋˜๋ฉด ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ๋‹ค์Œ ๋ฉ”์„œ๋“œ๋ฅผ ์‹คํ–‰ํ•œ๋‹ค. protected void service(HttpServletRequest request, HttpServletResponse response) HttpServletRequest ์—ญํ•  HTTP ์š”์ฒญ .. 2023. 8. 3.