Spring JDBC [3] ๊ฐ„๋‹จํ•œ ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ

2021. 11. 12. 14:28ใ†Spring

728x90

https://hyejin.tistory.com/250

 

Spring JDBC [1] DAO ํŒจํ„ด์ด๋ž€?, DataSource, JDBC, jdbcTemplate ํด๋ž˜์Šค

1. DAO(Data Access Object) ํŒจํ„ด ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๊ณ„์ธต์€ DAO ํŒจํ„ด์„ ์ ์šฉํ•˜์—ฌ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง๊ณผ ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๋กœ์ง์„ ๋ถ„๋ฆฌํ•˜๋Š” ๊ฒƒ์ด ์›์น™์ด๋ผ๊ณ  ํ•œ๋‹ค. DAO ํŒจํ„ด์€ ์„œ๋น„์Šค ๊ณ„์ธต์— ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š์œผ๋ฉด์„œ ๋ฐ

hyejin.tistory.com

https://hyejin.tistory.com/251

 

Spring JDBC [2] SPRING JDBC ํ™˜๊ฒฝ์„ค์ •ํ•˜๊ธฐ (Oracle JDBC ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜, Spring JDBC ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ค์น˜, DataSour

1. DB ๊ณ„์ • ๋ฐ ํ…Œ์ด๋ธ” ์ƒ์„ฑํ•˜๊ธฐ 1๏ธโƒฃ ๊ด€๋ฆฌ์ž๋กœ ๋กœ๊ทธ์ธํ•˜์—ฌ scott์ด๋ผ๋Š” ๊ณ„์ • ์ƒ์„ฑํ•˜๊ธฐ 2๏ธโƒฃ scott์ด๋ผ๋Š” ๊ณ„์ •์— ๊ถŒํ•œ ๋ถ€์—ฌํ•ด์ฃผ๊ธฐ 3๏ธโƒฃ ํ…Œ์ด๋ธ” ์ƒ์„ฑํ•˜๊ธฐ 4๏ธโƒฃ ํ…Œ์ด๋ธ”์— ๋ฐ์ดํ„ฐ ์‚ฝ์ž… ํ›„ commit ํ•˜๊ธฐ 5

hyejin.tistory.com

 

์œ„์— ๊ณผ์ •๊นŒ์ง€ ์ง„ํ–‰ํ•œ ํ›„์— ์ด์ œ ์ •๋ง ์ดˆ๊ฐ„๋‹จ ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ๋ฅผ ๋งŒ๋“ค์–ด๋ณผ ๊ฒƒ์ด๋‹ค!

์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ๋ผ๊ณ  ํ•˜๊ธฐ์—๋„ ๋ฏผ๋งํ•œ,, ใ…Žใ…Ž 

CRUD์— ๋งž์ถฐ์„œ ๋งŒ๋“ค์–ด ๋ณผ ๊ฒƒ์ด๋‹ค.

ํ™”๋ฉด ๊ตฌํ˜„์€ ์—†์œผ๋‹ˆ ์ฐธ๊ณ ๋งŒ ํ•˜์‹œ๊ธธ~..

 

1. ํ•„์š”ํ•œ ํด๋ž˜์Šค๋“ค

(์—ฌ๊ธฐ์„œ 2 ๋ถ™์€๊ฑด ํ•œ๋ฒˆ ๋” ์—ฐ์Šตํ•˜๋Š๋ผ ๊ทธ๋Ÿฐ๊ฒƒ์ด๋‹ค..)

1๏ธโƒฃ ์„œ๋น„์Šค ๊ณ„์ธต 

UserService2 ์ธํ„ฐํŽ˜์ด์Šค 

: ์„œ๋น„์Šค ๊ณ„์ธต์— ์†ํ•œ ์ƒ์œ„ ์ธํ„ฐํŽ˜์ด์Šค

 

UserServiceImpl2 ํด๋ž˜์Šค 

: UserService2๋ฅผ ๊ตฌํ˜„ํ•œ ํด๋ž˜์Šค๋กœ ๋ณต์žกํ•œ ์—…๋ฌด ๋กœ์ง์ด ์žˆ์„ ๊ฒฝ์šฐ์—๋Š” ์ด ํด๋ž˜์Šค์—์„œ ์—…๋ฌด ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค.

๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๊ณ„์ธต์˜ UserDAO2 ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•œ ๊ฐ์ฒด๋ฅผ IoC์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฃผ์ž…ํ•ด์ค€๋‹ค. 

 

2๏ธโƒฃ ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๊ณ„์ธต 

UserDAO2 ์ธํ„ฐํŽ˜์ด์Šค 

: ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๊ณ„์ธต์— ์†ํ•œ ์ƒ์œ„ ์ธํ„ฐํŽ˜์ด์Šค 

 

UserDaoJDBC2 ํด๋ž˜์Šค 

: UserDAO2 ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ตฌํ˜„ํ•œ ํด๋ž˜์Šค๋กœ ์ด ํด๋ž˜์Šค์—์„œ๋Š” ๋ฐ์ดํ„ฐ ์•ก์„ธ์Šค ๋กœ์ง์„ ๊ตฌํ˜„ํ•˜๋ฉด ๋œ๋‹ค. 

Spring JDBC๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๊ฒฝ์šฐ์—๋Š” DataSource๋ฅผ IoC ์ปจํ…Œ์ด๋„ˆ๊ฐ€ ์ฃผ์ž…ํ•ด์ค€๋‹ค. 

 

3๏ธโƒฃ ๋„๋ฉ”์ธ ๋ชจ๋ธ ํด๋ž˜์Šค 

UserVO ํด๋ž˜์Šค 

 

4๏ธโƒฃ ๋นˆ ์„ค์ • ํŒŒ์ผ

beans2.xml 

 

5๏ธโƒฃ ํ…Œ์ŠคํŠธ ํŒŒ์ผ 

UserClient2 ํด๋ž˜์Šค 

 

 

 

2. ์‚ฌ์šฉ์ž ๊ด€๋ฆฌ ํ”„๋กœ์ ํŠธ ๊ตฌํ˜„ 

 

1๏ธโƒฃ UserVO2

 

2๏ธโƒฃ  UserService2

 

3๏ธโƒฃ UserServiceImpl2

 

4๏ธโƒฃ UserDAO2

 

5๏ธโƒฃ UserDaoJDBC2

6๏ธโƒฃ  beans2.xml

7๏ธโƒฃ UserClient2

@Ignore๋“ค์„ ๋ถ™์—ฌ๋‘” ์ด์œ ๋Š” ํ•œ๋ฒˆ ํ…Œ์ŠคํŠธํ•˜๋ฉด ๋ฐ์ดํ„ฐ๋“ค์ด ๋“ค์–ด๊ฐ€์žˆ์–ด์„œ ์—๋Ÿฌ๋œฌ๋‹ค!

ํ•˜๋‚˜์”ฉ ์‹คํ–‰ํ•ด๋ณด๊ธธ,,~

 

3. ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ 

insertUserTest() ๊ฒฐ๊ณผ
selectUserTest() ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ
updateUserTest() ๊ฒฐ๊ณผ
deleteUserTest() ํ…Œ์ŠคํŠธ ๊ฒฐ๊ณผ 

 

728x90