๋ถ๋ฅ ์ ์ฒด๋ณด๊ธฐ (135) ์ธ๋ค์ผํ ๋ฆฌ์คํธํ Entity Life Cycle reference ์คํํธ ์คํ๋ง ๋ถํธ - ๊ตฌ๋ฉ๊ฐ๊ฒ ์ฝ๋ฉ๋จ New(๋น์์) Java์์ญ์ ๊ฐ์ฒด๋ง ์กด์ฌํ๊ณ , ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ฐ๋๋ ์ ์ด ์๋ ์ํ. ์ํฐํฐ ๋งค๋์ ์ ๊ด๋ฆฌํ์ ์๋ ๊ฒ์ด ์๋๊ธฐ ๋๋ฌธ์ ์์ํ Java ๊ฐ์ฒด Managed(์์) ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ์ ์ฅ๋๊ณ , ๋ฉ๋ชจ๋ฆฌ์์์๋ ๊ฐ์ ์ํ๋ก ์กด์ฌํ๋ ์ํ. ๊ฐ์ฒด๋ ์์ ์ปจํ ์คํธ ๋ด์ ๋ค์ด๊ฐ๊ฒ ๋๊ณ , id(PK)๊ฐ์ ํตํด์ ํ์ํ ์ํฐํฐ ๊ฐ์ฒด๋ฅผ ๊บผ๋ด ์ฌ์ฉํ ์ ์๊ฒ ๋ฉ๋๋ค. Removed(์ญ์ ) ๋ฐ์ดํฐ๋ฒ ์ด์ค์์์ ์ญ์ ๋ ์ํ. ๊ฐ์ฒด๋ ๋ ์ด์ ์์ ์ปจํ ์คํธ์ ์กด์ฌํ์ง ์์ต๋๋ค. Detached(์ค์์) ์์ ์ปจํ ์คํธ์์ ์ํฐํฐ ๊ฐ์ฒด๋ฅผ ๊บผ๋ด์ ์ฌ์ฉํ๋ ์ํ. ์ค์์ ์ํ์ ๊ฐ์ฒด๋ ๊ณ ์ ํ id(PK)๋ฅผ ๊ฐ์ง๊ณ ์์ง๋ง, ์์ง ๋ฐ์ดํฐ๋ฒ ์ด์ค์ ๋๊ธฐํ๊ฐ ์ด๋ฃจ์ด์ง์ง ์์.. Entity, Entity Manager reference ์คํํธ ์คํ๋ง ๋ถํธ - ๊ตฌ๋ฉ๊ฐ๊ฒ ์ฝ๋ฉ๋จ Entity Entity ์ฉ์ด๋ ๋ฐ์ดํฐ๋ฒ ์ด์ค์์์ ๋ฐ์ดํฐ๋ก ๊ด๋ฆฌํ๋ ๋์์ ์๋ฏธํ๋ค. ์๋ฅผ ๋ค์ด, ‘์ํ’, ‘ํ์ฌ’, ’์ง์’ ๋ฑ๊ณผ ๊ฐ์ด ๋ช ์ฌ์ด๋ฉด์ ์ ๋ฌด์ ๊ด๋ จ๋ ๋ฐ์ดํฐ๋ฅผ ์ํฐํฐ๋ก ๊ท์ ํ ์ ์๋ค. ๋ฐ์ดํฐ๋ฒ ์ด์ค์์๋ ์ํฐํฐ๋ฅผ ์ํด์ ์ผ๋ฐ์ ์ผ๋ก ํ ์ด๋ธ์ ์ค๊ณํ๊ณ , ๋ฐ์ดํฐ๋ฅผ ์ถ๊ฐํ๋ค. ์ด๋ ๊ฒ ์ถ๊ฐ๋ ๋ฐ์ดํฐ๋ ‘์ธ์คํด์ค’ ํน์ ‘๋ ์ฝ๋’๋ผ๋ ์ฉ์ด๋ก ๋ถ๋ฆฐ๋ค. Entity Manager ์ฌ๋ฌ Entity๋ค์ ๊ด๋ฆฌํ๋ ๊ฐ์ฒด ์์ ์ด ๊ด๋ฆฌํ๋ ๊ฐ์ฒด๋ค์ ‘์์ ์ปจํ ์คํธ(persistence context)’๋ด์ ๋ณด๊ดํ๊ณ ๊ฐ์ฒด์ life cycle์ ๊ด๋ฆฌํ๋ค. Data source ์ค์ , JPA ๊ด๋ จ ์ค์ reference ์คํํธ ์คํ๋ง ๋ถํธ - ๊ตฌ๋ฉ๊ฐ๊ฒ ์ฝ๋ฉ๋จ ์คํ๋ง ๋ถํธ ๊ฐ๋ ๊ณผ ํ์ฉ - ๋ฐฑ๊ธฐ์ application.properties ๋๋ application.yml ํ์ผ์ ์ค์ ํ ์ ์๋ค. DataSource ์ค์ ํ๊ธฐ JPA๋ MySQL๋ฑ์ ๋ฐ์ดํฐ๋ฒ ์ด์ค ๊ด๋ จ ๋ผ์ด๋ธ๋ฌ๋ฆฌ๊ฐ ์ถ๊ฐ๋๋ฉด Spring Boot๋ ์๋์ผ๋ก ์ค์ ์ ์ธ์ํ๊ธฐ ๋๋ฌธ์ ๋ฐ๋์ DataSource ์ค์ ์ด ํ์ํ๋ค. spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver spring.datasource.url=jdbc:mysql://localhost:3306/__dbname__?useSSL=false&serverTimezone=Asia/Seoul spring.datasource.user.. JPA Annotation reference ์คํํธ ์คํ๋ง ๋ถํธ - ๊ตฌ๋ฉ๊ฐ๊ฒ ์ฝ๋ฉ๋จ www.datanucleus.org/products/accessplatform/jpa/annotations.html code ๊ธฐ๋ณธ์ ์ผ๋ก lombok ์ ์ฌ์ฉํ์์ต๋๋ค. import ๋ฌธ๋ ๊ฐ์ด ๋ณผ ์ ์๋๋ก ์ฒจ๋ถํ์์ต๋๋ค. package org.zerock.domain; import java.sql.Timestamp; import javax.persistence.Entity; import javax.persistence.GeneratedValue; import javax.persistence.GenerationType; import javax.persistence.Id; import javax.persistence.Table; import org.h.. JPA reference ์คํํธ ์คํ๋ง ๋ถํธ - ๊ตฌ๋ฉ๊ฐ๊ฒ ์ฝ๋ฉ๋จ ์คํ๋ง ๋ถํธ ๊ฐ๋ ๊ณผ ํ์ฉ - ๋ฐฑ๊ธฐ์ ๋ JPA ์๊ฐ ๊ฐ์ฒด์ ๊ตฌ์กฐ์ ํ ์ด๋ธ์ ๊ตฌ์กฐ๊ฐ ์ ์ฌํ๋ค๋ ๊ฒ์์ ์์ JDBC๋ก ์ฒ๋ฆฌํ๋ ์์ ์ ํ๋์ ์ถ์ํ๋ ๊ณ์ธต ์ถ๊ฐ ORM, JPA, Spring Data JPA์ ๊ด๊ณ ORM(Object Relational Mapping) ๊ฐ์ฅ ์์ ๊ฐ๋ ์ ํด๋นํ๋ค. ๊ฐ์ฒด์งํฅ ํ๋ก๊ทธ๋๋ฐ์ RDBMS๊ตฌ์กฐ์ ์ฐ๊ฒฐ์์ผ ๊ฐ๋ฐํ์๋ ์ฌ์์ ๋ดํฌํ๊ณ ์๋ค. JPA(Java Persistence API) ORM์ ์ํ ์๋ฐ (EE) ํ์ค์ด๋ค. Java์ธ์ด๋ฅผ ์ด์ฉํด์ ORM์ ๊ตฌํํ๋ ค๊ณ ํ ๋ ์ง์ผ์ผ ํ๋ ์คํ์ด๋ผ๊ณ ํ ์ ์๋ค. Hibernate JPA์ ๊ตฌํ์ฒด๋ค ์ค์์ ํ๋์ ์ ํ์ด๊ณ spring boot์ ๊ฒฝ์ฐ ๊ธฐ๋ณธ์ ์ผ๋ก Hibe.. [spring boot] HATEOAS ๊ฐ๋จํ๊ฒ ์ฌ์ฉํด๋ณด๊ธฐ HATEOAS ๋? Hypermedia As The Engine Of Application State ์ ์ฝ์์ด๋ค. rest API์์, ์๋ฒ๋ ํ์ฌ ๋ฆฌ์์ค์ ์ฐ๊ด๋ ๋งํฌ ์ ๋ณด๋ฅผ ํด๋ผ์ด์ธํธ์๊ฒ ์ ๊ณตํ๋ค. ํด๋ผ์ด์ธํธ๋ ์ฐ๊ด๋ ๋งํฌ ์ ๋ณด๋ฅผ ๋ฐํ์ผ๋ก ๋ฆฌ์์ค์ ์ ๊ทผํ๋ค. ์ฐ๊ด๋ ๋งํฌ ์ ๋ณด: Relation Hypertext Reference; HATEOAS ๊ฐ๋จํ๊ฒ ์ฌ์ฉํด๋ณด๊ธฐ spring-boot-starter-hateoas ์์กด์ฑ ์ถ๊ฐ org.springframework.boot spring-boot-starter-hateoas Entity ์์ฑ @Getter @Setter @noargsconstructor public class Hello { private String prefix; private Strin.. [spring boot] ์์ฃผ ๊ฐ๋จํ๊ฒ Thymeleaf ์ฌ์ฉํด๋ณด๊ธฐ ํ ํ๋ฆฟ ์์ง์ด๋? ํ ํ๋ฆฟ ์์๊ณผ ํน์ ๋ฐ์ดํฐ ๋ชจ๋ธ์ ๋ฐ๋ฅธ ์ ๋ ฅ ์๋ฃ๋ฅผ ๊ฒฐํฉํ์ฌ ์ํ๋ ๊ฒฐ๊ณผ ๋ฌธ์๋ฅผ ์ถ๋ ฅํ๋ ์ํํธ์จ์ด(๋๋ ์ปดํฌ๋ํธ)๋ฅผ ๋งํ๋ค. ์ฃผ๋ก View๋ฅผ ๋ง๋ค ๋ ์ฌ์ฉํ๋ค. ๋์ ์ปจํ ์ธ ๋ฅผ ์์ฑํด์ ์ ๊ณตํด์ผํ ๋ ํ ํ๋ฆฟ ์์ง์ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์๋ค. Code Generation / Email Template ๋ฑ์ ์ฌ์ฉ๋๋ค. ์คํ๋ง ๋ถํธ๊ฐ ์๋ ์ค์ ์ ์ง์ํ๋ ํ ํ๋ฆฟ ์์ง FreeMarker Groovy Thymeleaf (์ถ์ฒ) ใ ก> ๋น๊ต์ ์ต๊ทผ์ ๋ง๋ค์ด์ง ํ ํ๋ฆฟ ์์ง์ด๋ค. Mustache JSP๋ฅผ ๊ถ์ฅํ์ง ์๋ ์ด์ spring boot๊ฐ ์งํฅํ๋ ๋ฐ๋ฅผ ์ถฉ์กฑ์ํค๊ธฐ ๋ชปํ๋ค. spring boot๋ ๋ ๋ฆฝ์ ์ผ๋ก ์คํ๊ฐ๋ฅํ embeded tomcat์ผ๋ก application์ ์ฝ๊ณ ๋น ๋ฅด๊ฒ ๋ง๋ค์ด ๋ฐฐํฌ.. [spring boot] index.html, favicon ์ฐ์ปด ํ์ด์ง application์ root๋ก ์์ฒญํ์ ๋ ๋ณด์ฌ์ฃผ๋ ํ์ด์ง์ด๋ค. 1. ๊ธฐ๋ณธ ๋ฆฌ์์ค ์์น์์ index.html ์ฐพ์ ๋ณด๊ณ ์์ผ๋ฉด ์ ๊ณตํ๊ณ 2. index.ํ ํ๋ฆฟ ์ฐพ์ ๋ณด๊ณ ์์ผ๋ฉด ์ ๊ณตํ๊ณ 3. ๋ ๋ค ์์ผ๋ฉด ์๋ฌ ํ์ด์ง๋ฅผ ๋ณด๋ด์ค๋ค. favicon ๋ธ๋ผ์ฐ์ ์ฐฝ ์ ๋ชฉ ์์ ์์ด์ฝ์ ์๋ฏธํ๋ค. favicon.ico ์ด๋ฆ์ผ๋ก ํด๋์ ์ถ๊ฐํ๋ค. ์ฝ๊ฒ favicon ๋ง๋ค๊ธฐ ์ฌ์ดํธ: https://favicon.io/ favicon์ด ์ ์ฉ์ด ๋์ง ์์ ๋๋ "๊ฐ๋ ฅํ ์๋ก๊ณ ์นจ(control + shift + R)"์ ํด๋ณด์ ! ! ! ๋๋ resources/static/ ์ ์ ์ฅํด๋์๋ค. ๋ด๊ฐ ์ ์ฉํ ๋ชจ์ต์ด๋ค. [spring boot] WebJars ์ค jquery ์ถ๊ฐํด๋ณด๊ธฐ WebJars๋? ํด๋ผ์ด์ธํธ์์ ์ฌ์ฉํ๋ ์น๋ผ์ด๋ธ๋ฌ๋ฆฌ(jquery, bootstrap, React.js, Vue.js, Angular ๋ฑ) ๋ฅผ *JAR* ํ์ผ ์์ ํจํค์งํ ๊ฒ์ด๋ค. ์คํ๋ง ๋ถํธ๋ WebJars์ ๋ํ ๊ธฐ๋ณธ mapping์ ์ ๊ณตํ๋ค. ์ฝ๊ฒ ๋งํด WebJars๋ฅผ ์ถ๊ฐํ ์ ์๋ค. mvn repository์ ์ฌ๋ผ์์๊ธฐ ๋๋ฌธ์ ๊ฒ์ํด์ pom.xml์ ์ถ๊ฐํ๊ณ ์ธ ์ ์๋ค. org.webjars.bower jquery 3.5.1 ๋ฒ์ ์๋ตํ๊ณ ์ฌ์ฉํ๋ ค๋ฉด webjars-locator-core ์์กด์ฑ ์ถ๊ฐํ๋ฉด ๋๋ค. org.webjars webjars-locator-core 0.46 [spring boot] ์ ์ ๋ฆฌ์์ค ์ง์ ์ ์ ๋ฆฌ์์ค๋? ํด๋ผ์ด์ธํธ๋ก๋ถํฐ ์์ฒญ์ด ๋ค์ด์์ ๋, ๋ฆฌ์์ค๊ฐ ์ด๋ฏธ ๋ง๋ค์ด์ ธ ์์ด์ ๊ทธ๋๋ก ๋ณด๋ด์ฃผ๋ฉด ๋๋ ๊ฒฝ์ฐ๋ฅผ ๋งํ๋ค. ๊ธฐ๋ณธ ๋ฆฌ์์ค ์์น “/**”์ด mapping์ ์ํด ์๋์ 4๊ฐ์ง ํด๋์ ์์ค์ ์ฐ๊ฒฐ์ด ๋๋ค. classpath:/static classpath:/public classpath:/resources/ classpath:/META-INF/resources ์์) /hello.html => /static/hello.html ๋งตํ ์ค์ ๋ณ๊ฒฝ ๊ฐ๋ฅ spring.mvc.static-path-pattern ์์) spring.mvc.static-path-pattern: /static/** => http://localhost:8080/static/hello.html ๋ฆฌ์์ค ์ฐพ์ ์์น ์ถ๊ฐ ๊ฐ๋ฅ We.. [spring boot] HttpMessageConverters HttpMessageConverters HTTP ์์ฒญ ๋ณธ๋ฌธ์ ๊ฐ์ฒด๋ก ๋ณ๊ฒฝํ๊ฑฐ๋, ๊ฐ์ฒด๋ฅผ HTTP ์๋ต ๋ณธ๋ฌธ์ผ๋ก ๋ณ๊ฒฝํ ๋ ์ฌ์ฉํ๋ค. ์คํ๋ง ํ๋ ์์ํฌ์์ ์ ๊ณตํ๋ ์ธํฐํ์ด์ค์ด๊ณ , ์คํ๋ง mvc์ ์ผ๋ถ๋ถ์ด๋ค. ์์) ์ปจํ ์ธ ํ์ ์ด json์ธ ์์ฒญ์ด ๋ค์ด์๋ค๋ฉด json message converter๊ฐ User๋ผ๋ ๊ฐ์ฒด๋ก ๋ณํํด์ค๋ค. {“username”:”keesun”, “password”:”123”} User ๋ฆฌํด ํ์ ์ด String์ด๋ฉด String message converter๊ฐ ์ฌ์ฉ์ด ๋๋ค. @ReuqestBody ์ @ResponseBody๋ฅผ ํตํด ์ง์ ํ ์ ์๋ค. @Controller public class UserController2 { @GetMapping("/hello") public @Re.. [spring boot] Test ์์กด์ฑ์ ํ์ธํ์ spring-boot-starter-test๊ฐ test ๊ธฐ๋ฅ์ ํด์ค๋ค. scope์ test๋ก ์ง์ ํ๋ฉด ๋๋ค. org.springframework.boot spring-boot-starter-test test test ๋ง๋ค๊ธฐ ๋จ์ถํค: Alt+Insert @SpringBootTest @SpringBootTest๋ Spring main application, ์ฆ @SpringBootApplication์ ์ฐพ์๊ฐ์ ์ดํ์ ๋ชจ๋ ๋น์ ์ค์บํ๊ณ test์ฉ application์ ๋ฑ๋กํ๋ค. ์ด๋ง์ด๋งํ ํตํฉํ ์คํธ์ธ ๊ฒ์ด๋ค. ๊ทธ๋ฆฌ๊ณ ๋ฐ์ ๋์ค์ง๋ง, MockBean๋ง ๊ต์ฒดํด์ค๋ค. ๊ฐ์ฅ ๊ธฐ๋ณธ์ ์ธ ํ ์คํธ ํํ๋ ์๋์ ๊ฐ๋ค. import org.junit.runner.RunWith; import org.s.. [spring boot] ๋ก๊ฑฐ๋ฅผ Log4j2๋ก ๋ณ๊ฒฝํ๊ธฐ docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html#howto-configure-log4j-for-logging “How-to” Guides Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework’s spring-jcl module. To use Logback, you need to include it and spring-jcl on the classpath. The recommended way to do th docs.spring.io org... [spring boot] logging ์ปค์คํฐ๋ง์ด์ง https://docs.spring.io/spring-boot/docs/current/reference/html/howto-logging.html “How-to” Guides Spring Boot has no mandatory logging dependency, except for the Commons Logging API, which is typically provided by Spring Framework’s spring-jcl module. To use Logback, you need to include it and spring-jcl on the classpath. The recommended way to do th docs.spring.io Customize log file Logback: ํ์ผ.. [spring boot] logging ๊ธฐ๋ณธ ์ค์ log: (ํ๋์ฌ) ์ผ์ง์ ๊ธฐ๋กํ๋ค (๋ง์ง๋ง ํ์ดํ) JUL(java util logging)์ SLF4j API๋ก ๋ณด๋ธ๋ค. (์ค๊ฐ ํ์ดํ) Log4J๋ SLF4j API๋ก ๋ณด๋ธ๋ค. (์ฒ์ ํ์ดํ) Logback์ด SLF4j์ ๊ตฌํ์ฒด์ด๋ค. Commons Logging, SLF4j๋ ์ค์ ๋ก๊น ์ ํ๋ ์ ๋ค์ด ์๋๋ผ ๋ก๊ฑฐ API๋ฅผ ์ถ์ํํด๋ interface ์ด๋ค. ์คํ๋ง ๋ถํธ๋ ๊ธฐ๋ณธ์ ์ผ๋ก Commons Logging์ ์ฌ์ฉํ๋๋ฐ ๊ฒฐ๊ตญ SLF4j์ ์ฌ์ฉํ๊ณ , SLF4j๋ ๊ตฌํ์ฒด์ธ Logback์ ์ฌ์ฉํ์ฌ ๋ก๊น (๊ธฐ๋ก)์ ํ๋ค. ์ต์ข ์ ์ผ๋ก Logback์ ์ด๋ค. ์คํ๋ง ๋ถํธ ๋ก๊น ์ ๊ธฐ๋ณธ ํฌ๋งท ๋ ์ง ์๊ฐ / ๋ก๊ทธ ๋ ๋ฒจ / PID / Thread ์ด๋ฆ / full package๊ฒฝ๋ก.class์ด๋ฆ / ๋ฉ์ธ์ง ๋๋ฒ๊น .. @Profile Spring Framework์์ ์ ๊ณตํด์ฃผ๋ ๊ธฐ๋ฅ์ด๋ค. ํน์ ํ ํ๋ก ํ์ผ์์๋ง ํน์ ํ ๋น์ ๋ฑ๋กํ๊ณ ์ถ๋ค๊ฑฐ๋ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋์์ ํน์ ํ ํ๋กํ์ผ์์ ๋น ์ค์ ์ ๋ค๋ฅด๊ฒ ํ๊ณ ์ถ์ ๋ ์ด๋ค. @Profile @Profile("prod") // ์ค์ ํ์ผ ์์ฒด๊ฐ "prod"๋ผ๋ ํ๋กํ์ผ์ผ ๋ ์ฌ์ฉ๋๋ค. ๊ทธ๋ฌ๋๊น ๋น์ฐํ hello ๋น๋ ๋ชป์ด๋ค. @Configuration public class BaseConfiguration { @Bean public String hello(){ return "hello"; } } @Profile("test") // ์ค์ ํ์ผ ์์ฒด๊ฐ "test"๋ผ๋ ํ๋กํ์ผ์ผ ๋ ์ฌ์ฉ๋๋ค. @Configuration public class TestConfiguration { @Bean publi.. [spring boot] ์ธ๋ถ ์ค์ https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config ์ธ๋ถ ์ค์ ์ด๋? ์ ํ๋ฆฌ์ผ์ด์ ์์ ์ฌ์ฉํ๋ ์ฌ๋ฌ ์ค์ ๊ฐ๋ค์ ์ ํ๋ฆฌ์ผ์ด์ ์ ๋๋ ๋ฐ์๋ค๊ฐ ์ ์ํ ์ ์๋ ๊ธฐ๋ฅ application.properties ๊ฐ์ฅ ์ค์ํ ์ค์ ํ์ผ์ application.properties ํ์ผ์ด๋ค. spring boot๊ฐ ์๋์ผ๋ก ๋ก๋ฉํ๋ ํ์ผ ์ด๋ฆ์ผ๋ก, ๊ท์ฝ(convention)์ด๋ค. key value ํํ๋ก ์ ์ํ๋ค. ๋ค ๋ฌธ์์ด์ด๋ค. springboot intializr ์ ์๋์ผ๋ก ์์ฑ๋๋ ํ์ผ๋ก, ๋ฐ์ ์ฐ์ ์์์์ 15์์์ ํด๋นํ๋ค. Spring Boot์ ์ธ๋ถ ์ค์ ์ข ๋ฅ propertie.. 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() ๋ฉ์๋๋ฅผ ํตํด ๋ค์ํ ์์ฒญ ์ฒ๋ฆฌ๋ฅผ ๊ตฌํํ ์ ์๋ค. ์ด์ 1 2 3 4 5 6 7 ๋ค์