๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
IT/WEB

[38์ผ์ฐจ] ๊ฒŒ์‹œํŒ ๋งŒ๋“ค๊ธฐ

by GWLEE 2022. 8. 12.

๐Ÿ’™2022-08-12๐Ÿ’™

 

mysql 

local ๊ณ„์ • ctrl + enter

 

root ๊ณ„์ •

 

์ถ”์ถ”๊ฐ€

 

 

mysql ๋ฒ„์ „ ํ™•์ธ 8.0.29

 

 

Persistence Framework

์ง€์†์„ฑ ํ”„๋ ˆ์ž„์›Œํฌ

 

์ง€์†์„ฑ ํ”„๋ ˆ์ž„์›Œํฌ(Persistence Framework)๋Š” ๋ฐ์ดํ„ฐ์˜ ์ €์žฅ, ์กฐํšŒ, ๋ณ€๊ฒฝ, ์‚ญ์ œ๋ฅผ ๋‹ค๋ฃจ๋Š” ํด๋ž˜์Šค ๋ฐ ์„ค์ • ํŒŒ์ผ๋“ค์˜ ์ง‘ํ•ฉ์ด๋‹ค. ์ง€์†์„ฑ ํ”„๋ ˆ์ž„์›Œํฌ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด JDBC ํ”„๋กœ๊ทธ๋ž˜๋ฐ์˜ ๋ณต์žกํ•จ์ด๋‚˜ ๋ฒˆ๊ฑฐ๋กœ์›€ ์—†์ด ๊ฐ„๋‹จํ•œ ์ž‘์—…๋งŒ์œผ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ์—ฐ๋™๋˜๋Š” ์‹œ์Šคํ…œ์„ ๋น ๋ฅด๊ฒŒ ๊ฐœ๋ฐœํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ ์•ˆ์ •์ ์ธ ๊ตฌ๋™๋„ ๋ณด์žฅํ•œ๋‹ค.

 

1) SQL mapping 

IDํ•˜๊ณ  sql ๋งคํ•‘ํ•ด์„œ ์“ฐ๋Š” ๊ฑฐ . ๋Œ€ํ‘œ์ ์œผ๋กœ MyBatis๊ฐ€ ์žˆ๋‹ค. ์šฐ๋ฆฌ๋Š” ์ด๊ฒƒ์„ ์“ธ ๊ฒƒ

 

2) ORM(Object Relation Mapping)

 

์š”์ฆ˜ ๊ฐ๊ด‘๋ฐ›๋Š” ๋ฐฉ๋ฒ•. ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ํ•˜๋‚˜์˜ ๋ ˆ์ฝ”๋“œ๋ฅผ VO ํด๋ž˜์Šค ์ฒ˜๋Ÿผ ํ•˜๋‚˜์˜ ๊ฐ์ฒด๋กœ ๋“ค๊ณ ์˜จ๋‹ค. ์‚ฌ์šฉ์ž๋Š” ์ฟผ๋ฆฌ๋ฌธ์„ ์“ฐ๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ ๊ฐ์ฒด์˜ setter getter๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค. ํ”„๋กœ๊ทธ๋ž˜๋จธ ์ž…์žฅ์—์„œ๋Š” ์ฟผ๋ฆฌ๋ฌธ์„ ์ „ํ˜€ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š”๋‹ค. ๊ตฌ์กฐ๋กœ๋Š” DB๊ฐ€ ์žˆ์œผ๋ฉด ORM์ด ์กด์žฌํ•˜๊ณ  ์†Œ์Šค์ฝ”๋“œ์—์„œ newํ•˜๊ณ  ๊ฐ์ฒด ๋งŒ๋“ค๊ณ  ์ถ”๊ฐ€ ๋ฉ”์„œ๋“œ๋งŒ ๋ชจ๋ธ์— ์ง‘์–ด ๋„ฃ์€ ์ƒํƒœ์—์„œ ์ค‘๊ฐ„์— ์ฟผ๋ฆฌ๋ฌธ์œผ๋กœ ๋ฐ”๊พผ๋‹ค. ์ง€๊ฐ€ ์•Œ์•„์„œ ํ•ด์„ํ•ด์„œ ๊ฐ€์ ธ๋‹ค๊ฐ€ ์ค€๋‹ค. ์ฝ”๋“œ์ƒ์—์„œ๋Š” sql์ด ์•ˆ๋“ค์–ด๊ฐ„๋‹ค. ์ด๋ ‡๊ฒŒ ํ•˜๋ฉด ์žฅ์ ์ด ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ๋ฐ”๊พธ๋ฉด ORM์ด ๋งก์€ ๋ถ€๋ถ„๋งŒ ์„ค์ •ํ•˜๋ฉด ๋œ๋‹ค. JPA java pasistence API .. ์‚ฌ์šฉ๋ฐฉ๋ฒ•์„ ์ฃผ์žฅ. JPA ๊ตฌํ˜„ํ•œ ๋Œ€ํ‘œ์ ์ธ๊ฒŒ Hibenate๊ฐ€ ์žˆ๋‹ค. ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์Šคํ”„๋ง์€ spring - data - jpa ๊ฐ€ ์žˆ๋‹ค. 

 

 

 

https://mvnrepository.com/artifact/org.mybatis/mybatis-spring/2.0.7

https://mvnrepository.com/artifact/org.mybatis/mybatis/3.5.10

 

 

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
	<modelVersion>4.0.0</modelVersion>
	<groupId>com.gyuone</groupId>
	<artifactId>BoardProject</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>war</packaging>
	<build>
		<plugins>
			<plugin>
				<artifactId>maven-compiler-plugin</artifactId>
				<version>3.8.1</version>
				<configuration>
					<release>11</release>
				</configuration>
			</plugin>
			<plugin>
				<artifactId>maven-war-plugin</artifactId>
				<version>3.2.3</version>
			</plugin>
		</plugins>
	</build>
	<dependencies>
		<!-- https://mvnrepository.com/artifact/javax.servlet/javax.servlet-api -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>javax.servlet-api</artifactId>
			<version>4.0.1</version>
			<scope>provided</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/javax.servlet.jsp/javax.servlet.jsp-api -->
		<dependency>
			<groupId>javax.servlet.jsp</groupId>
			<artifactId>javax.servlet.jsp-api</artifactId>
			<version>2.3.3</version>
			<scope>provided</scope>
		</dependency>
		<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
		<dependency>
			<groupId>javax.servlet</groupId>
			<artifactId>jstl</artifactId>
			<version>1.2</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.springframework/spring-webmvc -->
		<dependency>
			<groupId>org.springframework</groupId>
			<artifactId>spring-webmvc</artifactId>
			<version>5.3.22</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.29</version>
		</dependency>
		<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.5.10</version>
		</dependency>

		<!-- https://mvnrepository.com/artifact/org.mybatis/mybatis-spring -->
		<dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis-spring</artifactId>
			<version>2.0.7</version>
		</dependency>

	</dependencies>

</project>

 

๋Œ“๊ธ€