SpringBoot 2.7.2 , Java11 ์ฌ์ฉ
1. H2 Database ์ฌ์ฉ ์ค์
- build.gradle
dependencies {
...
// https://mvnrepository.com/artifact/com.h2database/h2
implementation group: 'com.h2database', name: 'h2', version: '2.1.214'
// https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jdbc
implementation group: 'org.springframework.boot', name: 'spring-boot-starter-data-jdbc', version: '2.7.1'
...
}
- application.yml
spring:
application:
name: sample
datasource:
hikari:
# ๋ฉ๋ชจ๋ฆฌ ์ฌ์ฉํ์ฌ ๊ตฌ๋
jdbc-url: jdbc:h2:mem:h2-test
driver-class-name: org.h2.Driver
username: sa
password:
maximum-pool-size: 10
h2:
console: # h2 ์ฝ์ ์ฌ์ฉ ์ต์
enable: true
path: /h2-console
2. CSV ํ์ผ ๊ฒฝ๋ก
src/resources ๋ฐ์ schema.sql ์ด ์กด์ฌํ๋ค๊ณ ๊ฐ์ ์, ํด๋น ํ์ผ๊ณผ ๋์ผํ ์์น์ ํ์ผ์ ์์ฑํ๋ค.
- ํ์ผ ๊ตฌ์กฐ ์์
3. Schema.sql ์์ฑ
์์) ๋ฐ์ดํฐ๋ฒ ์ด์ค ํ ์ด๋ธ ์์ฑ ํ๋ฉด์ ๋ฐ์ดํฐ ๋ฐ์ด๋ฃ์.
- H2 Database 'CSVREAD' ํจ์ ํ์ฉ(http://h2database.com/html/tutorial.html#csv)
- Schema.sql
CREATE TABLE IF NOT EXISTS bank_user AS SELECT * FROM CSVREAD('classpath:bank_user.csv');
ํด๋์คํจ์ค(classpath) ๋ฅผ ์ฌ์ฉํ์ฌ ์ง์ ๋ ์์น์์ ํ์ผ์ ์ฐพ์์ฌ ์ ์๊ฒ๋ ๊ตฌ์ฑ.
"D:\test.csv" ์ ๊ฐ์ด ์ ๋ ๊ฒฝ๋ก๋ ์ฌ์ฉ ๊ฐ๋ฅํ๋, ๋ณธ์ธ๋ง ์ฌ์ฉํ ๊ฒ์ด ์๋๋ผ๋ฉด ์ด๋ ๊ฒ ๊ตฌ์ฑํ๋ฉด ๋ถํธํ๊ธฐ ๋๋ฌธ์
์๋ ๊ฒฝ๋ก๋ก ์์ฑํ์ฌ ๋ถํธํจ์ ๋ ์ ์๋๋ก ํ๋ค.
- ๊ฒฐ๊ณผ ํ์ธ
http://localhost:8080/h2-console ๋ก ์ ์ํ์ฌ ํ์ธ.
'๐ฎSpring' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[SpringBoot] Swagger ui 3.0 ์ฐ๋ํ๊ธฐ (0) | 2022.07.18 |
---|---|
[SpringBoot] Rest Api Sample ๋ง๋ค๊ธฐ #2 (0) | 2022.07.05 |
[SpringBoot] Rest Api Sample ๋ง๋ค๊ธฐ #1 (0) | 2022.07.05 |
[SpringBoot] CORS ์ฒ๋ฆฌํ๊ธฐ (0) | 2022.06.28 |
[AOP] AOP Aspect ๋ฅผ ์ด์ฉํ ๋ก๊ทธ ์ฒ๋ฆฌ ํ๊ธฐ (0) | 2022.04.18 |
๋๊ธ