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

Spring/Spring Quick Start

(45)
JPA ํ”„๋กœ์ ํŠธ Spring Quick Start(์ฑ…)์˜ Day5 class04~05 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์‹ค์Šตํ•œ ์ฝ”๋“œ์˜ ๋งํฌ์ž…๋‹ˆ๋‹ค. JPA๋ž€? ORM ํ”„๋ ˆ์ž„์›Œํฌ๋“ค์— ๋Œ€ํ•œ ํ‘œ์ค€ํ™” ์ž‘์—…์˜ ๊ฒฐ๊ณผ๊ฐ€ JPA์ด๋‹ค. JPA(Java Persistence API)๋Š” ๋ชจ๋“  ORM ๊ตฌํ˜„์ฒด(ORM ํ”„๋ ˆ์ž„์›Œํฌ)๋“ค์˜ ๊ณตํ†ต ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ œ๊ณตํ•œ๋‹ค. JDBC๋Š” Oracle, Mysql, H2 ๋“ฑ ํŠน์ • DBMS์— ์ข…์†๋˜์ง€ ์•Š๋Š” DB ์—ฐ๋™ ๊ตฌํ˜„์„ ์ง€์›ํ•œ๋‹ค. ์ด์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ JPA API(javax.persistence)๋ฅผ ์ด์šฉํ•˜๋ฉด ๊ฐœ๋ฐœ ๋‹น์‹œ์—๋Š” Hibernate๋ฅผ ORM ํ”„๋ ˆ์ž„์›Œํฌ๋กœ ์‚ฌ์šฉํ•˜๋‹ค๊ฐ€ ์‹ค์ œ ์„œ๋น„์Šค๊ฐ€ ์‹œ์ž‘๋  ๋•Œ๋Š” TopLink๋กœ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค. ===== JPA ํ”„๋กœ์ ํŠธ ์ž‘์„ฑ๋ฐฉ๋ฒ• ===== 1. maven ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ 2...
Mybatis ํ”„๋กœ์ ํŠธ Spring Quick Start(์ฑ…)์˜ Day5 class01~02 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์‹ค์Šตํ•œ ์ฝ”๋“œ์˜ ๋งํฌ์ž…๋‹ˆ๋‹ค. Mybatis ํ”„๋ ˆ์ž„์›Œํฌ์˜ ์ค‘์š”ํ•œ ํŠน์ง• ํ•œ ๋‘์ค„์˜ ์ž๋ฐ” ์ฝ”๋“œ๋กœ dB ์—ฐ๋™์„ ์ฒ˜๋ฆฌํ•œ๋‹ค SQL ๋ช…๋ น์–ด๋ฅผ java ์ฝ”๋“œ์—์„œ ๋ถ„๋ฆฌํ•˜์—ฌ XML ํŒŒ์ผ์— ๋”ฐ๋กœ ๊ด€๋ฆฌํ•œ๋‹ค. Mybatis ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ Data Mapper๋ผ๊ณ  ๋ถ€๋ฅธ๋‹ค. Mybatis๋Š” xmL ํŒŒ์ผ์— ์ €์žฅ๋œ SQL ๋ช…๋ น์–ด๋ฅผ ๋Œ€์‹  ์‹คํ–‰ํ•˜๊ณ  ์‹คํ–‰ ๊ฒฐ๊ณผ๋ฅผ VO ๊ฐ™์€ ๊ฐ์ฒด์— ์ž๋™์œผ๋กœ ๋งคํ•‘๊นŒ์ง€ ํ•ด์ค€๋‹ค. ====Mybatis ํ”„๋กœ์ ํŠธ ์ž‘์„ฑ๋ฐฉ๋ฒ•==== 1. pom.xml์— dependency ๋“ฑ๋กํ•˜๊ธฐ mysql mysql-connector-java 8.0.21 org.mybatis mybatis 3.5.6 org.apache.ibatis..
์„œ๋ธ”๋ฆฟ ๊ฐ์ฒด์˜ service() ๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๋Š” ๊ณผ์ • ๐Ÿ’ ์„œ๋ธ”๋ฆฟ ๊ฐ์ฒด์˜ service() ๋ฉ”์†Œ๋“œ๊ฐ€ ํ˜ธ์ถœ๋˜๋Š” ๊ณผ์ • ๐Ÿง€ ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ํด๋ผ์ด์–ธํŠธ์˜ http ์š”์ฒญ์ด ์„œ๋ฒ„์— ์ „๋‹ฌ๋˜๋Š” ์ˆœ๊ฐ„ ๐Ÿง€ HttpServletRequest ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜๊ณ  HTTP ํ”„๋กœํ† ์ฝœ์— ๋ชจ๋“  ์ •๋ณด๋ฅผ ์ถ”์ถœํ•˜์—ฌ HttpServletRequest ๊ฐ์ฒด์— ์ €์žฅํ•œ๋‹ค. (doGet(), doPost(), service() ๋ฉ”์†Œ๋“œ๊ฐ€ ์ •์ƒ์œผ๋กœ ํ˜ธ์ถœ๋˜๋ ค๋ฉด HttpServletRequest ์™€ HttpServletResponse ๊ฐ์ฒด๊ฐ€ ํ•„์š”ํ•˜๋‹ค.) ๐Ÿง€ ์ด HttpServletRequest ๊ฐ์ฒด๋ฅผ service() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•  ๋•Œ ์ธ์ž๋กœ ์ „๋‹ฌํ•ด์ค€๋‹ค. ๐Ÿง€ ๊ทธ๋ž˜์„œ service() ๋ฉ”์†Œ๋“œ๋ฅผ ํ†ตํ•ด ๋‹ค์–‘ํ•œ ์š”์ฒญ ์ฒ˜๋ฆฌ๋ฅผ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.
์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ์˜ ๊ด€๊ณ„ Spring Quick Start(์ฑ…)์˜ Day4 class03 ์„ ๊ณต๋ถ€ํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ๊ฐœ์ธ์ ์œผ๋กœ ์•„์ฃผ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์ด๋ผ๊ณ  ์ƒ๊ฐํ•ฉ๋‹ˆ๋‹ค! characterEncoding org.springframework.web.filter.CharacterEncodingFilter encoding EUC-KR characterEncoding *.do contextConfigLocation classpath:applicationContext.xml org.springframework.web.context.ContextLoaderListener dispatcher org.springframework.web.servlet.DispatcherServlet contextConfigLocation classpath:dispatche..
intelliJ ํ†ฐ์บฃ ์„œ๋ฒ„๋กœ ์‹คํ–‰ํ•˜๊ธฐ 1. add Configuration Template์—์„œ Tomcat Server > Local Warning์ด ๋œจ๋Š”๋ฐ ์˜†์— ๋นจ๊ฐ„ ์ „๊ตฌ๋กœ Fix ๋ถ€๋ถ„์„ ๋ˆ„๋ฅด๋ฉด war์™€ war:exploded๊ฐ€ ๋œฌ๋‹ค. ๋ฐ‘์— ๊ฒƒ์„ ํด๋ฆญํ•œ๋‹ค. Application context์— "/๋ธŒ๋ผ์šฐ์ €์—์„œํ˜ธ์ถœ๋˜๊ธธ์›ํ•˜๋Š”ํ”„๋กœ์ ํŠธ์ด๋ฆ„" ์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ๋‹ค. 2. ์ด๋ ‡๊ฒŒ ์„ค์ •์„ ๋‹ค ํ•˜๊ณ  ์ ์šฉํ•˜๋ฉด Run button(์ดˆ๋ก์ƒ‰ ์„ธ๋ชจ ๋ฒ„ํŠผ)์ด ํ™œ์„ฑํ™”๋œ๋‹ค. ๋ˆŒ๋Ÿฌ๋ณด์ž!
IntelliJ๋กœ, Spring ํ”„๋กœ์ ํŠธ(maven) ์ƒ์„ฑํ•˜๊ธฐ ๐Ÿ’ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ 1. maven์˜ webapp์œผ๋กœ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•œ๋‹ค. maven์„ ์ด์šฉํ•˜์—ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ๊ด€๋ฆฌ๊ฐ€ ๊ฐ€๋Šฅํ•œ pom.xml ํŒŒ์ผ๊ณผ webapp ๋””๋ ‰ํ† ๋ฆฌ ๋ฐ‘์— webapplication ์„ค์ •์„ ์œ„ํ•œ web.xml ํŒŒ์ผ์ด ์ƒ์„ฑ๋œ๋‹ค. 2. pom.xml์— ์„ ์ถ”๊ฐ€ํ•˜์—ฌ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. ์Šคํ”„๋ง 5.3.2๋กœ ์ž‘์„ฑํ–ˆ๋˜ pom.xml์€ ์—ฌ๊ธฐ์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค. 16๋ฒˆ์งธ ์ค„ ์ดํ›„ (properties)๋กœ ๋ณต๋ถ™ํ•ด์ค€๋‹ค. ๋ฐ‘์— ๋ฒ„ํŠผ ํด๋ฆญํ•˜๋ฉด reload ๋œ๋‹ค. 3. Spring MVC ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ถ”๊ฐ€ํ•œ๋‹ค. ๋ฃจํŠธํด๋” ์šฐํด๋ฆญ ํ›„ > Add Frameworks Support > Spring MVC ํ•˜๋ฉด webapp directory์— applicationContext.xml์™€ dispatcher-servlet...
IntelliJ Add Framework Support์— Spring์ด ๋ณด์ด์ง€ ์•Š์„ ๋•Œ IntelliJ Add Framework Support์— Spring์ด ๋ณด์ด์ง€ ์•Š์„ ๋•Œ ์ฆ‰, ๋ฐ‘์— ๋ถ€๋ถ„์ด ๋ณด์ด์ง€ ์•Š์„ ๋•Œ๋Š” File > Project Structure (ctrl + alt + shift + s) ์— ๋“ค์–ด๊ฐ€์„œ Facets > Spring ํด๋ฆญ > ์‚ญ์ œ๋ฒ„ํŠผ ๋ˆ„๋ฅด๊ธฐ ๋‹ค์‹œ Add Framework Support์— ๋“ค์–ด๊ฐ€๋ฉด Spring ๊ด€๋ จ ๋ฉ”๋‰ด๋“ค์ด ์ƒ๊ธด ๊ฒƒ์„ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋‹ค.
์–ด๋…ธํ…Œ์ด์…˜์„ ์ ์šฉํ•œ Spring MVC ๊ฒŒ์‹œํŒ ๊ฐœ๋ฐœ Spring Quick Start(์ฑ…)์˜ Day4 class01~02 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์‹ค์Šตํ•œ ์ฝ”๋“œ์˜ ๋งํฌ์ž…๋‹ˆ๋‹ค. 1. ์ปจํŠธ๋กค๋Ÿฌ ๊ฐ์ฒด์— @Controller ๋“ฑ๋กํ•˜๊ธฐ @Controller๋กœ ๋“ฑ๋ก๋œ ์ปดํฌ๋„ŒํŠธ๊ฐ€ ์Šค์บ”๋˜๊ธฐ ์œ„ํ•ด ์Šคํ”„๋ง ์„ค์ • ํŒŒ์ผ(webapp/WEB-INF/presentation-layer.xml)์— ์œผ๋กœ ํŒจํ‚ค์ง€ ์œ„์น˜๋ฅผ ์ง€์ •ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค. ์ปจํŠธ๋กค๋Ÿฌ ํด๋ž˜์Šค์— @Component๋ฅผ ์ƒ์†ํ•œ @Controller๋ฅผ ๋“ฑ๋กํ•œ๋‹ค. 2. @RequestMapping ์‚ฌ์šฉํ•˜๋ฉด์„œ Controller ํ†ตํ•ฉํ•˜๊ธฐ @RequestMapping ์Šคํ”„๋ง์—์„œ๋Š” @RequestMapping์„ ์ด์šฉํ•˜์—ฌ HandlerMapping ์„ค์ •์„ ๋Œ€์ฒดํ•œ๋‹ค. HandlerMapping ์€ ์ด์ „์— ์Šคํ”„๋ง ์„ค์ • ํŒŒ์ผ์—์„œ ์ง€..
๊ฒ€์ƒ‰๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•˜๋Š” ๊ฐ์ฒด: HttpSession, HttpServletRequest, ModelAndView ์Šคํ”„๋ง MVC๋ฅผ ์ ์šฉํ•˜์—ฌ Controller๋ฅผ ์ž‘์„ฑํ•˜๋˜ ์ค‘ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋ฅผ ์ €์žฅํ•ด๋‘๋Š” ๊ฐ์ฒด์— ๋Œ€ํ•ด์„œ ์ด์•ผ๊ธฐํ•ด๋ณด๋ ค ํ•œ๋‹ค. import javax.servlet.http.HttpSession; HttpSession๋Š” ํด๋ผ์ด์–ธํŠธ ๋ธŒ๋ผ์šฐ์ € ํ•˜๋‚˜๋‹น ํ•˜๋‚˜์”ฉ ์„œ๋ฒ„ ๋ฉ”๋ชจ๋ฆฌ์— ์ƒ์„ฑ๋˜์–ด ํด๋ผ์ด์–ธํŠธ์˜ ์ƒํƒœ์ •๋ณด๋ฅผ ์œ ์ง€ํ•˜๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์ด๋‹ค. ์„ธ์…˜์— ๋งŽ์€ ์ •๋ณด๊ฐ€ ์ €์žฅ๋˜๋ฉด ๋ ์ˆ˜๋ก ์„œ๋ฒ„์— ๋ถ€๋‹ด์„ ์ค„ ์ˆ˜ ๋ฐ–์— ์—†๋‹ค. import javax.servlet.http.HttpServletRequest; ๊ทธ๋ž˜์„œ ๊ฒ€์ƒ‰ ๊ฒฐ๊ณผ๋Š” HttpServletRequest์— ์ €์žฅํ•˜๋Š” ๊ฒƒ์ด ๋งž๋‹ค. HttpServletRequest๋Š” ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์œผ๋กœ ์ƒ์„ฑ๋๋‹ค๊ฐ€ ์‘๋‹ต๋ฉ”์„ธ์ง€๊ฐ€ ํด๋ผ์ด์–ธํŠธ๋กœ ์ „์†ก๋˜๋ฉด ์ž๋™์œผ๋กœ ์‚ญ์ œ๋˜๋Š” ์ผํšŒ์„ฑ ๊ฐ์ฒด์ด๋‹ค. ๊ทธ๋Ÿฌ๋ฏ€๋กœ ์„œ๋ฒ„์— ๋ถ€๋‹ด์„ ..
์Šคํ”„๋ง ์ธ์ฝ”๋”ฉ ์„ค์ • ์Šคํ”„๋ง์—์„œ๋Š” ์ธ์ฝ”๋”ฉ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด CharacterEncodingFilter ํด๋ž˜์Šค๋ฅผ ์ œ๊ณตํ•œ๋‹ค. web.xml ํŒŒ์ผ์— CharacterEncodingFilter๋ฅผ ๋“ฑ๋กํ•˜๋ฉด ๋ชจ๋“  ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ์— ๋Œ€ํ•ด์„œ ์ผ๊ด„์ ์œผ๋กœ ์ธ์ฝ”๋”ฉ์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. [web.xml ์ค‘] characterEncoding org.springframework.web.filter.CharacterEncodingFilter encoding EUC-KR characterEncoding *.do ๋Š” ๊ณผ ๊ฑฐ์˜ ๋น„์Šทํ•œ ํ˜•ํƒœ๋กœ ๋“ฑ๋กํ•œ๋‹ค.
WEB-INF/action-servlet.xml ํŒŒ์ผ ์ด๋ฆ„ ๋ณ€๊ฒฝํ•˜๋Š” ๋ฐฉ๋ฒ• action org.springframework.web.servlet.DispatcherServlet action *.do web.xml์—์„œ servlet-name์ด action์ด๋ผ์„œ "WEB-INF/action-servlet.xml"์ด ๊ธฐ๋ณธ์ ์ธ DispatcherServlet ์„ค์ • ํŒŒ์ผ์ด๋‹ค. DispatcherServlet์˜ ์„ค์ • ํŒŒ์ผ ์ด๋ฆ„์„ ๋ฐ”๊พธ๊ณ  ์‹ถ๋‹ค๋ฉด action org.springframework.web.servlet.DispatcherServlet contextConfigLocation /WEB-INF/config/presentation-layer.xml action *.do init-param์œผ๋กœ contextConfigLocation ์ง€์ •ํ•˜๊ณ  /WEB-INF/config/์›ํ•˜๋Š”_ํŒŒ์ผ_์ด๋ฆ„ ..
Spring MVC๋ฅผ ์ ์šฉํ•œ ๊ฒŒ์‹œํŒ ๊ฐœ๋ฐœ Spring Quick Start(์ฑ…)์˜ Day3 class05~07 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์‹ค์Šตํ•œ ์ฝ”๋“œ์˜ ๋งํฌ์ž…๋‹ˆ๋‹ค. 1. DispatcherServlet ๋“ฑ๋ก WEB-INF/web.xml ํŒŒ์ผ์— ์Šคํ”„๋ง ํ”„๋ ˆ์ž„์›Œํฌ์—์„œ ์ œ๊ณตํ•˜๋Š” DispatcherServlet ๋“ฑ๋กํ•˜๊ธฐ ์„œ๋ธ”๋ฆฟ ์ปจํ…Œ์ด๋„ˆ๋Š” ํด๋ผ์ด์–ธํŠธ์˜ ".do" ์š”์ฒญ์ด ์žˆ์–ด์•ผ DispatcherServlet ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•œ๋‹ค. [web.xml] action org.springframework.web.servlet.DispatcherServlet action *.do 2. ์Šคํ”„๋ง ์ปจํ…Œ์ด๋„ˆ ๊ตฌ๋™ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ์œผ๋กœ DispatcherServlet ๊ฐ์ฒด๊ฐ€ ์ƒ์„ฑ๋œ๋‹ค. DispatcherServlet์€ ํด๋ผ์ด์–ธํŠธ์˜ ์š”์ฒญ ์ฒ˜๋ฆฌ์— ํ•„์š”ํ•œ HandlerMa..
EL & JSTL ๋ž€? EL: Expression Language JSP 2.0์—์„œ ์ƒˆ๋กœ ์ถ”๊ฐ€๋œ ์Šคํฌ๋ฆฝํŠธ ์–ธ์–ด๋กœ์„œ, ๊ธฐ์กด์˜ ํ‘œํ˜„์‹์„ ๋Œ€์ฒดํ•˜๋Š” ํ‘œํ˜„์–ธ์–ด์ด๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด session์— ์ €์žฅ๋˜์–ด ์žˆ๋Š” ์‚ฌ์šฉ์ž ์ด๋ฆ„์„ JSP ํ™”๋ฉด์— ์ถœ๋ ฅํ•  ๋•Œ, ๊ธฐ์กด์—๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ‘œํ˜„ํ–ˆ๋‹ค๋ฉด, EL์„ ์ด์šฉํ•˜๋ฉด ์•„๋ž˜์™€ ๊ฐ™์ด ํ‘œํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค. ${userName} ์•„๋ž˜์˜ ์ฝ”๋“œ์—์„œ ๊ฐ„๊ฐ„ํžˆ ${ } ๋ฅผ ์ด์šฉํ•˜์—ฌ ๊ฐ’์„ ์“ฐ๊ณ  ์žˆ๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค. [ getBoard.jsp ] ๊ธ€ ์ƒ์„ธ Log-out ์ œ๋ชฉ ์ž‘์„ฑ์ž ${board.writer } ๋‚ด์šฉ ${board.content } ๋“ฑ๋ก์ผ ${board.regDate } ์กฐํšŒ์ˆ˜ ${board.cnt } ๊ธ€๋“ฑ๋ก ๊ธ€์‚ญ์ œ ๊ธ€๋ชฉ๋ก JSTL: JSP Standard Tag Library JSP ํ”„๋กœ๊ทธ๋žจ์„ ๊ฐœ๋ฐœํ•˜๋‹ค ๋ณด๋ฉด ..
MVC๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ํ•˜์—ฌ ๊ฒŒ์‹œํŒ ๊ฐœ๋ฐœ Spring Quick Start(์ฑ…)์˜ Day3 class04 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. Spring MVC๋ฅผ ์ ์šฉํ•˜๊ธฐ ์ „, ๋™์ผํ•œ ๊ตฌ์กฐ๋กœ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์ง์ ‘ ๊ตฌํ˜„ํ•ด๋ณด๋ ค๊ณ  ํ•œ๋‹ค. MVC ํ”„๋ ˆ์ž„์›Œํฌ ๊ตฌ์กฐ๋Š” ์•„๋ž˜์™€ ๊ฐ™๋‹ค. ๐Ÿง€ ๋กœ๊ทธ์ธ ๊ธฐ๋Šฅ ๋™์ž‘ ๊ณผ์ • ๐Ÿง€ 1. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋กœ๊ทธ์ธ ๋ฒ„ํŠผ์„ ํด๋ฆญํ•˜์—ฌ "/login.do" ์š”์ฒญ์„ ์ „์†กํ•˜๋ฉด DispatcherServlet์ด ์š”์ฒญ์„ ๋ฐ›๋Š”๋‹ค. 2. DispatcherServlet์€ HandlerMapping ๊ฐ์ฒด๋ฅผ ํ†ตํ•ด ๋กœ๊ทธ์ธ ์š”์ฒญ์„ ์ฒ˜๋ฆฌํ•  LoginController๋ฅผ ๊ฒ€์ƒ‰ํ•˜๊ณ , 3. ๊ฒ€์ƒ‰๋œ LoginController์˜ handelRequest() ๋ฉ”์†Œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋ฉด ๋กœ๊ทธ์ธ ๋กœ์ง์ด ์ฒ˜๋ฆฌ๋œ๋‹ค. 4. ๋กœ๊ทธ์ธ ์ฒ˜๋ฆฌ ํ›„์— ์ด๋™ํ•  ํ™”๋ฉด ์ •๋ณด๊ฐ€ ๋ฆฌํ„ด๋˜๋ฉด 5. Dispat..
intelliJ์—์„œ servlet ์ƒ์„ฑํ•˜๊ธฐ ๋ถ„๋ช… ๋‚˜๊ฐ™์€ ์‚ฌ๋žŒ์ด ์žˆ์„ ๊ฒƒ์ด๋‹ค. Servlet ํŒŒ์ผ์„ ์ƒ์„ฑํ•˜๋ ค๊ณ  ํ•˜๋Š”๋ฐ ๋ˆˆ์„ ์”ป๊ณ  ์ฐพ์•„๋ด๋„ Servlet ํŒŒ์ผ์ด ์—†๋‹ค. ๊ฒ€์ƒ‰ํ•ด๋ณด๋ฉด ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค์€ Servlet ํŒŒ์ผ์„ ์„ ํƒํ•ด์„œ ๋ฐ”๋กœ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋˜๋ฐ ๋ง์ด๋‹ค. ํด๋ž˜์Šค๋กœ ๋งŒ๋“ค๊ณ  ์ง์ ‘ ์จ์•ผ ํ•˜๋‚˜ ๋ง‰๋ง‰ํ•  ๊ฒƒ์ด๋‹ค. Servlet ์„ ์ƒ์„ฑํ•˜๋Š” ๋ฐฉ๋ฒ• 1. ์ž๋ฐ” ํด๋ž˜์Šค ๋งŒ๋“ ๋‹ค. 2. ์„œ๋ธ”๋ฆฟ์€ ํ•ญ์ƒ HttpServlet์„ ์ƒ์†๋ฐ›๊ธฐ์— "extends HttpServlet"์„ ์ง์ ‘ ์จ์ค€๋‹ค. 3. ์šฐํด๋ฆญ > generate(์•ŒํŠธ+insert) > Override Methods๋ฅผ ๋ˆŒ๋Ÿฌ ์›ํ•˜๋Š” ๋ฉ”์†Œ๋“œ๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋”ฉํ•˜๋ฉด ๋œ๋‹ค. ์™œ ๋‹ค๋ฅธ ์‚ฌ๋žŒ๋“ค๊ณผ ๋‹ค๋ฅธ์ง€ ์ž˜ ๋ชจ๋ฅด๊ฒ ๋‹ค. new > Servlet ์„ค์ •์ด ์žˆ์œผ๋ ค๋ฉด ํ”„๋กœ์ ํŠธ์˜ Facets์— web์ด ์ถ”๊ฐ€๋˜์–ด ์žˆ์–ด์•ผ ํ•˜๋Š” ๊ฒƒ ๊ฐ™๋‹ค. ์ถ”๊ฐ€๋กœ, ..
[์—๋Ÿฌ] intelliJ Server ์‚ฌ์šฉ ์‹œ output์ฐฝ ํ•œ๊ธ€ ๊นจ์ง ์˜ค๋ฅ˜ run configuration์˜ vm options์— -Dfile.encoding=UTF-8 ์•„๋ž˜์™€ ๊ฐ™์ด ํ•œ๊ธ€์ด ์ž˜ ์ถœ๋ ฅ๋˜๋Š” ๊ฒƒ์„ ๋ณผ ์ˆ˜ ์žˆ๋‹ค.
forward์™€ redirect ์ฐจ์ด ํฌ์›Œ๋“œ RequestDispatcher๋ฅผ ์ด์šฉํ•˜์—ฌ ์‘๋‹ต์œผ๋กœ ์‚ฌ์šฉํ•  JSPํ™”๋ฉด์œผ๋กœ ๋„˜๊ฒจ์„œ, ํฌ์›Œ๋“œ๋œ ํ™”๋ฉด์ด ํด๋ผ์ด์–ธํŠธ์— ์ „์†ก๋˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ํ•œ๋ฐ˜์˜ ์š”์ฒญ๊ณผ ์‘๋‹ต์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๋ฏ€๋กœ ์‹คํ–‰ ์†๋„๊ฐ€ ๋น ๋ฅด๋‹ค. ํด๋ผ์ด์–ธํŠธ ๋ธŒ๋ผ์šฐ์ €์˜ URL์ด ๋ฐ”๋€Œ์ง€ ์•Š์•„ ์‘๋‹ต์ด ์–ด๋””์—์„œ ๋“ค์–ด์™”๋Š”์ง€ ํ™•์ธํ•  ์ˆ˜ ์—†๋‹ค. ๋ฆฌ๋‹ค์ด๋ ‰ํŠธ ์š”์ฒญ๋œ JSP์—์„œ ์ผ๋‹จ ๋ธŒ๋ผ์šฐ์ €๋กœ ์‘๋‹ต ๋ฉ”์‹œ์ง€๋ฅผ ๋ณด๋ƒˆ๋‹ค๊ฐ€ ๋‹ค์‹œ ์„œ๋ฒ„๋กœ ์žฌ์š”์ฒญํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ํฌ์›Œ๋“œ๋ฐฉ์‹๊ณผ ๋‹ค๋ฅด๊ฒŒ ์ผ๋‹จ ์‘๋‹ต์ด ๋ธŒ๋ผ์šฐ์ €๋กœ ๋“ค์–ด๊ฐ„ ๋‹ค์Œ, ์žฌ์š”์ฒญํ•˜๋Š” ๋ฐฉ์‹์ด๋‹ค. ์‘๋‹ต์ด ๋“ค์–ด์˜จ ํŒŒ์ผ๋กœ ๋ธŒ๋ผ์šฐ์ €์˜ URL์ด ๋ณ€๊ฒฝ๋œ๋‹ค. ๋‘๋ฒˆ์˜ ์š”์ฒญ๊ณผ ์‘๋‹ต์œผ๋กœ ์ฒ˜๋ฆฌ๋˜๋ฏ€๋กœ ์‹คํ–‰ ์†๋„๋Š” ํฌ์›Œ๋“œ ๋ฐฉ์‹๋ณด๋‹ค ๋Š๋ฆฌ๋‹ค.
Model 2 ์•„ํ‚คํ…์ณ๋กœ ๊ฒŒ์‹œํŒ ๊ฐœ๋ฐœ (Controller์˜ ๋“ฑ์žฅ) Spring Quick Start(์ฑ…)์˜ Day3 class03 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. Model 2 ์•„ํ‚คํ…์ฒ˜ ๊ตฌ์กฐ ํ•ต์‹ฌ์€ Controller์˜ ๋“ฑ์žฅ์ด๋‹ค. ๊ธฐ์กด Model 1์—์„œ๋Š” JSP๊ฐ€ Controller์™€ View ๊ธฐ๋Šฅ ๋ชจ๋‘๋ฅผ ๋‹ด๋‹นํ–ˆ๋Š”๋ฐ Model 2 JSP๋Š” ๋””์ž์ธ๊ณผ ๊ฐ™์€ View๋ฅผ ๋‹ด๋‹นํ•˜๊ณ , Servlet ํด๋ž˜์Šค๊ฐ€ Controller๋ฅผ ๋‹ด๋‹นํ•œ๋‹ค. MVC ์•„ํ‚คํ…์ณ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ๋ถ€๋ถ„์ด Controller์ด๋‹ค. Controller๋ฅผ ์„ฑ๋Šฅ๊ณผ ์œ ์ง€๋ณด์ˆ˜์˜ ํŽธ์˜์„ฑ์„ ๊ณ ๋ คํ•˜์—ฌ ์ž˜ ๋งŒ๋“œ๋Š” ๊ฒƒ์ด ๋ฌด์—‡๋ณด๋‹ค ์ค‘์š”ํ•˜๋‹ค. ์ •๋ฆฌํ•˜๋ฉด ์ด๋ ‡๋‹ค. ์ธ์ฝ”๋”ฉ ์ž‘์—…์„ DispatcherServlet ํด๋ž˜์Šค์—์„œ ์ผ๊ด„ ์ฒ˜๋ฆฌํ•˜๋ฏ€๋กœ ์ธ์ฝ”๋”ฉ์„ ๋ณ€๊ฒฝํ•  ๋•Œ๋Š” DispatcherServlet ํด๋ž˜์Šค๋งŒ ์ˆ˜์ •ํ•˜๋ฉด ๋œ๋‹ค. ๊ธ€ ๋“ฑ๋ก, ์ˆ˜..
Model 1 ์•„ํ‚คํ…์ณ๋กœ ๊ฒŒ์‹œํŒ ๊ฐœ๋ฐœ (JSP์™€ JavaBeans๋งŒ์„ ์‚ฌ์šฉ) Spring Quick Start(์ฑ…)์˜ Day3 class01~02 ์‹ค์Šต์„ ์ง„ํ–‰ํ•˜๋ฉด์„œ ๊ธฐ๋กํ•œ ๋‚ด์šฉ์ž…๋‹ˆ๋‹ค. ์‹ค์Šต ์ฝ”๋“œ๋Š” ์—ฌ๊ธฐ์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค. Model 1 Architecture ๊ตฌ์กฐ 90๋…„๋Œ€ ๋ง๋ถ€ํ„ฐ 2000๋…„๋Œ€ ์ดˆ๊นŒ์ง€ ์ž๋ฐ” ๊ธฐ๋ฐ˜์˜ ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์— ์‚ฌ์šฉ๋˜์—ˆ๋˜ ์•„ํ‚คํ…์ณ์ด๋‹ค. JSP์™€ JavaBeans๋งŒ ์‚ฌ์šฉํ•œ ๋ชจ๋ธ์ด๋‹ค. Model: ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๋™ ๋กœ์ง์„ ์ œ๊ณตํ•˜๋ฉด์„œ DB์—์„œ ๊ฒ€์ƒ‰ํ•œ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ๋˜๋Š” ์ž๋ฐ” ๊ฐ์ฒด๋ฅผ ์˜๋ฏธํ•œ๋‹ค. ์•ž์„  ์‹ค์Šต์—์„œ VO(๋˜๋Š” DTO)์™€ DAO ํด๋ž˜์Šค๊ฐ€ ๋ฐ”๋กœ Model ๊ธฐ๋Šฅ์˜ ์ž๋ฐ” ๊ฐ์ฒด์ด๋‹ค. View: JSP ์ฝ”๋“œ ์ค‘์—์„œ๋„ ์‚ฌ์šฉ์ž๊ฐ€ ์›ํ•˜๋Š” ํ™”๋ฉด์„ ์ œ๊ณตํ•˜๊ธฐ ์œ„ํ•ด HTML์™€ CSS๋ฅผ ์‚ฌ์šฉํ•œ ๋ถ€๋ถ„์ด view ๊ธฐ๋Šฅ์„ ๋‹ด๋‹นํ•œ๋‹ค. Controller: JSP ํŒŒ์ผ์— ์ž‘์„ฑ๋œ ์ž๋ฐ” ์ฝ”..
ํŠธ๋žœ์žญ์…˜(Transaction) ์ ์šฉ 1. ํŠธ๋žœ์žญ์…˜ ๋„ค์ž„์ŠคํŽ˜์ด์Šค ๋“ฑ๋ก ํŠธ๋žœ์žญ์…˜์„ ์œ„ํ•ด xmlns:tx๋ฅผ ์ถ”๊ฐ€ํ–ˆ๋‹ค. [ applicationContext.xml ] 2. ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ์ž ๋“ฑ๋ก ๋ชจ๋“  Transaction ๊ด€๋ฆฌ์ž๋Š” PlatformTransactionManager interface๋ฅผ ๊ตฌํ˜„ํ•œ ํด๋ž˜์Šค์ด๋‹ค. ๋ชจ๋“  Transaction ๊ด€๋ฆฌ์ž๋Š” Transaction ๊ด€๋ฆฌ์— ํ•„์š”ํ•œ commit(), rollback() ๋ฉ”์†Œ๋“œ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ๋‹ค. public interface PlatformTransactionManager{ TransactionStatus getTransaction(TransactionDefinition definition) throws TransactionException; void commit(TransactionStatus..