Spring boot

[Spring Boot] Bank App (1) - ํ”„๋กœ์ ํŠธ ์„ค์ •

๋ฏธ๋กœ910 2024. 8. 12. 09:05
๐Ÿ’ก Bank App ํ”„๋กœ์ ํŠธ์˜ ๋ชฉํ‘œ

Spring Boot ํ”„๋ ˆ์ž„์›Œํฌ ๊ธฐ๋ฐ˜: Spring Boot์˜ ๊ธฐ๋ณธ ๋™์ž‘ ์›๋ฆฌ๋ฅผ ์ดํ•ดํ•˜๊ณ  ํ™œ์šฉํ•ฉ๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด, ๊ฐœ๋ฐœ์ž๋Š” Spring Boot๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋น ๋ฅด๊ณ  ํšจ์œจ์ ์œผ๋กœ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

MVC ํŒจํ„ด ๊ตฌํ˜„: JSP(JavaServer Pages) ํ…œํ”Œ๋ฆฟ ์—”์ง„์„ ์‚ฌ์šฉํ•˜์—ฌ MVC(Model-View-Controller) ํŒจํ„ด์„ ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. MVC ํŒจํ„ด์„ ํ†ตํ•ด ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ๊ตฌ์กฐ๋ฅผ ๋ช…ํ™•ํ•˜๊ฒŒ ๋ถ„๋ฆฌํ•จ์œผ๋กœ์จ, ์œ ์ง€๋ณด์ˆ˜์„ฑ๊ณผ ํ™•์žฅ์„ฑ์ด ํ–ฅ์ƒ๋ฉ๋‹ˆ๋‹ค.

๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง ์ƒ์„ฑ: ํ”„๋กœ์ ํŠธ ๋‚ด์—์„œ ํ•„์š”ํ•œ ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์„ค๊ณ„ํ•˜๊ณ  ๊ตฌํ˜„ํ•ฉ๋‹ˆ๋‹ค. ์ด ๊ณผ์ •์—์„œ Spring Boot์˜ ๋‹ค์–‘ํ•œ ๊ธฐ๋Šฅ์„ ํ™œ์šฉํ•˜์—ฌ, ์š”๊ตฌ ์‚ฌํ•ญ์„ ์ถฉ์กฑํ•˜๋Š” ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ๊ฐœ๋ฐœํ•ฉ๋‹ˆ๋‹ค.

DB ์ ‘๊ทผ ๊ธฐ์ˆ  ํ™œ์šฉ: ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค(MyBatis)๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ ‘๊ทผ ๊ธฐ์ˆ ์„ ํ•™์Šตํ•˜๊ณ  ์ ์šฉํ•ฉ๋‹ˆ๋‹ค. MyBatis๋ฅผ ํ™œ์šฉํ•จ์œผ๋กœ์จ, SQL ์ฟผ๋ฆฌ๋ฅผ ๋ณด๋‹ค ์‰ฝ๊ฒŒ ์ž‘์„ฑํ•˜๊ณ  ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€์˜ ์ƒํ˜ธ์ž‘์šฉ์„ ํšจ์œจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•ฉ๋‹ˆ๋‹ค.

์ด ํ”„๋กœ์ ํŠธ๋Š” Spring Boot์™€ JSP๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ MVC ํŒจํ„ด์„ ๊ตฌํ˜„ํ•˜๊ณ , ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์„ ์ƒ์„ฑํ•˜๋Š” ๋™์‹œ์—, MyBatis๋ฅผ ํ†ตํ•œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ ‘๊ทผ ๋ฐฉ๋ฒ•์„ ํƒ๊ตฌํ•˜๋Š” ๊ฒƒ์„ ๋ชฉํ‘œ๋กœ ํ•ฉ๋‹ˆ๋‹ค.

 

ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
dependencies {
	implementation 'org.springframework.boot:spring-boot-starter-web'
	implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3'
	compileOnly 'org.projectlombok:lombok'
	developmentOnly 'org.springframework.boot:spring-boot-devtools'
	runtimeOnly 'com.h2database:h2'
	runtimeOnly 'com.mysql:mysql-connector-j'
	annotationProcessor 'org.projectlombok:lombok'
	providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
	testImplementation 'org.springframework.boot:spring-boot-starter-test'
	testImplementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.3'
	testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
}

 

mybatis ๋ฒ„์ „ 3.x.x ์ด์ƒ ์ด์–ด์•ผ ์ •์ƒ ๋™์ž‘ ํ•ฉ๋‹ˆ๋‹ค.

https://mybatis.org/mybatis-3/ko/index.html

 

mybatis – ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค 3 | ์†Œ๊ฐœ

๋งˆ์ด๋ฐ”ํ‹ฐ์Šค๋Š” ๋ฌด์—‡์ธ๊ฐ€? ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค๋Š” ๊ฐœ๋ฐœ์ž๊ฐ€ ์ง€์ •ํ•œ SQL, ์ €์žฅํ”„๋กœ์‹œ์ € ๊ทธ๋ฆฌ๊ณ  ๋ช‡๊ฐ€์ง€ ๊ณ ๊ธ‰ ๋งคํ•‘์„ ์ง€์›ํ•˜๋Š” ํผ์‹œ์Šคํ„ด์Šค ํ”„๋ ˆ์ž„์›Œํฌ์ด๋‹ค. ๋งˆ์ด๋ฐ”ํ‹ฐ์Šค๋Š” JDBC๋กœ ์ฒ˜๋ฆฌํ•˜๋Š” ์ƒ๋‹น๋ถ€๋ถ„์˜ ์ฝ”๋“œ์™€

mybatis.org

 

ํ˜ธํ™˜ ๋ฒ„์ „ ํ™•์ธ

https://mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/index.html

 

mybatis-spring-boot-autoconfigure – Introduction

Introduction Translations Users can read about MyBatis-Spring-Boot-Starter in the following translations: What is MyBatis-Spring-Boot-Starter? The MyBatis-Spring-Boot-Starter help you build quickly MyBatis applications on top of the Spring Boot. By using t

mybatis.org

 

JSP๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์˜์กด์„ฑ ์ถ”๊ฐ€

// ์˜์กด์„ฑ ์ถ”๊ฐ€ 
implementation 'org.apache.tomcat.embed:tomcat-embed-jasper'
// implementation 'javax.servlet:jstl' spring 3.x.x ๋ฒ„์ „์—์„œ ์‚ฌ์šฉ ์•ˆ๋จ
implementation group: 'org.glassfish.web', name: 'jakarta.servlet.jsp.jstl', version: '3.0.0'

Spring Boot๋Š” ์ž„๋ฒ ๋””๋“œ ์„œ๋ฒ„ ํ™˜๊ฒฝ์—์„œ JSP๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ธฐ๋ณธ์ ์œผ๋กœ ์ง€์›ํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.

Spring Boot๋Š” ์ฃผ๋กœ Thymeleaf, FreeMarker์™€ ๊ฐ™์€ ๋‹ค๋ฅธ ํ…œํ”Œ๋ฆฟ ์—”์ง„์„ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•ฉ๋‹ˆ๋‹ค. ๊ทธ๋Ÿฌ๋‚˜ ์—ฌ์ „ํžˆ JSP๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด, ๋ช‡ ๊ฐ€์ง€ ์ถ”๊ฐ€์ ์ธ ์„ค์ •๊ณผ ์˜์กด์„ฑ์„ ํ”„๋กœ์ ํŠธ์— ํฌํ•จ์‹œ์ผœ์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

์˜์กด์„ฑ ์„ค๋ช…

- **`org.springframework.boot:spring-boot-starter-web`**: Spring Boot ์›น ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ์Šคํƒ€ํ„ฐ ํŒจํ‚ค์ง€์ž…๋‹ˆ๋‹ค. ์ด๋Š” Spring MVC์™€ ํ•จ๊ป˜ ์ž„๋ฒ ๋””๋“œ Tomcat ์„œ๋ฒ„๋ฅผ ํฌํ•จํ•˜๋ฉฐ, RESTful ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‰ฝ๊ฒŒ ๊ตฌ์ถ•ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
- **`org.mybatis.spring.boot:mybatis-spring-boot-starter:3.0.3`**: MyBatis๋ฅผ Spring Boot์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•œ ์Šคํƒ€ํ„ฐ์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด MyBatis์™€ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์—ฐ๋™ ์ž‘์—…์„ ์†์‰ฝ๊ฒŒ ์„ค์ •ํ•˜๊ณ  ์ง„ํ–‰ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- **`org.projectlombok:lombok`**: Java ํ”„๋กœ์ ํŠธ์—์„œ ๋ณด์ผ๋Ÿฌํ”Œ๋ ˆ์ดํŠธ ์ฝ”๋“œ๋ฅผ ์ค„์ด๊ธฐ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. ์–ด๋…ธํ…Œ์ด์…˜์„ ์‚ฌ์šฉํ•˜์—ฌ ์ž๋™์œผ๋กœ getter, setter, toString ๋“ฑ์˜ ๋ฉ”์„œ๋“œ๋ฅผ ์ƒ์„ฑํ•ด ์ค๋‹ˆ๋‹ค.
- **`org.springframework.boot:spring-boot-devtools`**: ๊ฐœ๋ฐœ ์ค‘์— ์œ ์šฉํ•œ ์—ฌ๋Ÿฌ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋Š” Spring Boot์˜ ์ถ”๊ฐ€ ๋„๊ตฌ์ž…๋‹ˆ๋‹ค. ์˜ˆ๋ฅผ ๋“ค์–ด, ์ž๋™ ๋ฆฌ์Šคํƒ€ํŠธ ๊ธฐ๋Šฅ์ด ์žˆ์–ด ํŒŒ์ผ ๋ณ€๊ฒฝ ์‹œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์ž๋™์œผ๋กœ ์žฌ์‹œ์ž‘ํ•ด ์ค๋‹ˆ๋‹ค.
- **`com.h2database:h2`**: ์ธ๋ฉ”๋ชจ๋ฆฌ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋กœ, ๊ฐœ๋ฐœ ๋ฐ ํ…Œ์ŠคํŠธ ๋ชฉ์ ์œผ๋กœ ์ฃผ๋กœ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค. ์„ค์น˜ ์—†์ด ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๋‚ด๋ถ€์—์„œ ์‹คํ–‰๋˜๋ฏ€๋กœ ํ…Œ์ŠคํŠธ ํ™˜๊ฒฝ ๊ตฌ์„ฑ์ด ์šฉ์ดํ•ฉ๋‹ˆ๋‹ค.
- **`com.mysql:mysql-connector-j`**: MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์—ฐ๊ฒฐํ•˜๊ธฐ ์œ„ํ•œ JDBC ๋“œ๋ผ์ด๋ฒ„์ž…๋‹ˆ๋‹ค. ์ด๋ฅผ ํ†ตํ•ด Spring Boot ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์ด MySQL ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์™€ ํ†ต์‹ ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
- **`annotationProcessor 'org.projectlombok:lombok'`**: Lombok ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์ปดํŒŒ์ผ ์‹œ์ ์— ์–ด๋…ธํ…Œ์ด์…˜์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ๋„๋ก ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
- **`org.springframework.boot:spring-boot-starter-test`**: ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ์Šคํƒ€ํ„ฐ ํŒจํ‚ค์ง€๋กœ, JUnit, Spring Test, Mockito ๋“ฑ์„ ํฌํ•จํ•˜์—ฌ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์˜ ํ…Œ์ŠคํŠธ๋ฅผ ์ง€์›ํ•ฉ๋‹ˆ๋‹ค.
- **`org.mybatis.spring.boot:mybatis-spring-boot-starter-test:3.0.3`**: MyBatis์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ํ…Œ์ŠคํŠธ ์ง€์› ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์ž…๋‹ˆ๋‹ค. MyBatis ๊ธฐ๋ฐ˜์˜ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋ฅผ ํ…Œ์ŠคํŠธํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.
- **`org.apache.tomcat.embed:tomcat-embed-jasper`**: ์ด ์˜์กด์„ฑ์€ ์ž„๋ฒ ๋””๋“œ Tomcat ์„œ๋ฒ„์—์„œ JSP ํŒŒ์ผ์„ ์ปดํŒŒ์ผํ•˜๊ธฐ ์œ„ํ•ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค. Spring Boot๊ฐ€ ์‚ฌ์šฉํ•˜๋Š” ์ž„๋ฒ ๋””๋“œ ์„œ๋ฒ„ ํ™˜๊ฒฝ์—์„œ JSP ํŒŒ์ผ์„ ์ •์ƒ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•˜๊ณ  ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด ์ค๋‹ˆ๋‹ค.
- **`org.glassfish.web:jakarta.servlet.jsp.jstl:2.0.0`**: ์ด ์˜์กด์„ฑ์€ JSP ํ‘œ์ค€ ํƒœ๊ทธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ(JSTL)๋ฅผ ํ”„๋กœ์ ํŠธ์— ์ถ”๊ฐ€ํ•ฉ๋‹ˆ๋‹ค. JSTL์€ JSP ํŽ˜์ด์ง€์—์„œ ๋ฐ˜๋ณต๋ฌธ, ์กฐ๊ฑด๋ฌธ ๋“ฑ์˜ ๋กœ์ง์„ ์ฒ˜๋ฆฌํ•˜๋Š” ๋ฐ ์‚ฌ์šฉ๋˜๋Š” ํƒœ๊ทธ๋“ค์˜ ์ง‘ํ•ฉ์ž…๋‹ˆ๋‹ค. **`org.glassfish.web`** ๊ทธ๋ฃน์—์„œ ์ œ๊ณตํ•˜๋Š” **`jakarta.servlet.jsp.jstl`** ํŒจํ‚ค์ง€๋Š” JSP์—์„œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๋‹ค์–‘ํ•œ ํƒœ๊ทธ๋ฅผ ์ œ๊ณตํ•˜์—ฌ, JSP ํŽ˜์ด์ง€์˜ ๊ฐœ๋ฐœ์„ ๋”์šฑ ํŽธ๋ฆฌํ•˜๊ฒŒ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.