๐Ÿ“š TIL 21์ผ์ฐจ

temprmnยท2023๋…„ 6์›” 14์ผ
0
post-thumbnail

์˜ค๋Š˜์˜ ์ฃผ์š”์‚ฌํ•ญ (6/14, ์ˆ˜์š”์ผ)

  1. Spring ๋นจ๋ฆฌ ๋๋‚ด๊ณ  ๊ณผ์ œํ•ด์•ผํ•จ!!!

ํ”ผ๊ณคํ•˜๋‹ค๊ณ  ์กฐ๊ธˆ ๋ฏธ๋ค˜๋”๋‹ˆ ์ผ์ •์ด ์ด‰๋ฐ•ํ•ด์กŒ๋‹ค๐Ÿ˜‚ ์ด๋Ÿฌ๋‹ค๊ฐ„ ์•ผ๊ฐ„๋ณด์ถฉํ•™์Šต์„ ๋ฉดํ•  ์ˆ˜ ์—†๊ฒŒ ๋˜๊ณ  ๋งŒ๋‹ค๐Ÿ˜ต... ๋‹คํ–‰ํžˆ ๊ทผ์œก์ด์™„์ œ๋ฅผ ๋จน๊ณ  ์žค๋”๋‹ˆ ์ปจ๋””์…˜์ด ์กฐ๊ธˆ ํšŒ๋ณต๋˜์—ˆ๋‹ค. ์ •๋ง๋กœ ๊ทผ์œกํ†ต ๋•Œ๋ฌธ์ด์—ˆ๋˜ ๋“ฏ ์‹ถ๋‹ค...

ํ•˜์—ฌํŠผ 12์‹œ๊ฐ„๋™์•ˆ ์•‰์•„์„œ ๊ณต๋ถ€ํ•˜๋Š”๋งŒํผ, ์ปจ๋””์…˜์„ ํ‰ํƒ„ํ•˜๊ฒŒ ์œ ์ง€ํ•˜๊ณ  ์‹ถ์–ด์„œ ๋Šฆ๊ฒŒ ์ž๋Š” ๊ฒƒ๋งŒํผ์€ ํ”ผํ•˜๊ณ  ์žˆ๋‹ค (ใ… ใ… )... ๋˜๋„๋ก 11์‹œ ์ทจ์นจ โ†’ 6์‹œ ๊ธฐ์ƒ์„ ์ง€ํ‚ค๋ ค๊ณ  ๋…ธ๋ ฅํ•˜๊ณ  ์žˆ๋‹ค. ์˜ค๋Š˜๋„ ํŒŒ์ดํŒ… ๐Ÿ’ช๐Ÿ’ช!!

DTO๋ž€?

DTO = Data Transfer Object
๋ฐ์ดํ„ฐ ์ „์†ก ๋ฐ ์ด๋™์„ ์œ„ํ•ด ์ƒ์„ฑ๋˜๋Š” ๊ฐ์ฒด๋ฅผ ์˜๋ฏธํ•œ๋‹ค.

DTO

(1) Client์—์„œ ๋ณด๋‚ด์˜ค๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ์ฒด๋กœ ์ฒ˜๋ฆฌํ•  ๋•Œ๋„ ์‚ฌ์šฉ๋˜๊ณ , (2) ์„œ๋ฒ„์˜ ๊ณ„์ธต ๊ฐ„ ์ด๋™์—๋„ ์‚ฌ์šฉ๋œ๋‹ค. ๋˜, (3) DB์™€์˜ ์†Œํ†ต์„ ๋‹ด๋‹นํ•˜๋Š” ํด๋ž˜์Šค๋ฅผ DTO๋กœ ํ•œ ๋ฒˆ ๋ณ€ํ™˜ ํ›„ ๋ฐ˜ํ™˜ํ•  ๋•Œ๋„ ์‚ฌ์šฉ๋œ๋‹ค. (๊ทธ ์™ธ ์ž์„ธํ•œ ๊ฒƒ๋“ค์€ ์ดํ›„ ๊ฐ•์˜๋ฅผ ํ†ตํ•ด ์ž์—ฐ์Šค๋Ÿฝ๊ฒŒ ํ•™์Šตํ•  ์ˆ˜ ์žˆ๋‹ค)

Request ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•  ๋•Œ ์‚ฌ์šฉ๋˜๋Š” ๊ฐ์ฒด๋Š” RequestDto, Response๋ฅผ ๋‹ด๋‹นํ•˜๋Š” ๊ฐ์ฒด๋Š” ResponseDto๋ผ๋Š” ์ด๋ฆ„์„ ๋ถ™์ธ๋‹ค. ์ด๋Š” ์กฐ์ง์— ๋”ฐ๋ผ ๋ช…๋ช…๊ทœ์น™์ด ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋‹ค.

CLI ์ ์‘๊ธฐ ... #1


#1 ๋จธ๋ฆฌ๊ฐ€ ๋‚˜์˜๋ฉด ๋ชธ์ด ๊ณ ์ƒํ•œ๋‹ค.

๐Ÿˆ [Git] CLI ์ ์‘๊ธฐ #1

์•„๋ฌดํŠผ ์ด๋ ‡๊ฒŒ ์ฒซ ์ปค๋ฐ‹๊ณผ ํ‘ธ์‹œ๋Š” ๋ฌด์‚ฌํžˆ ๋๋ƒˆ๋‹ค. ๊ณ ์ž‘ ์ด๊ฑฐํ•˜๋Š”๋ฐ ์—๋Ÿฌ๋ฅผ 4๋ฒˆ์ •๋„ ๋ดค์Œ... ๊ทธ๋ƒฅ IntelliJ์—์„œ ์ปค๋ฐ‹ํ• ๊นŒ...........

MySQL ์ ์‘๊ธฐ #1


(๋Œ€์ถฉ ๋ฐ”๋ณด์ฒ˜๋Ÿผ ์—๋Ÿฌ ๋‚ด๊ณ ๋„ ๋ญ๊ฐ€ ๋ฌธ์ œ์ธ์ง€ ๋ชฐ๋ž๋‹ค๋Š” ๊ธ€) ๊ทธ๋ž˜๋„ ํ•ด๊ฒฐํ–ˆ์Šต๋‹ˆ๋‹ค!!!

๐Ÿฌ [MySQL] ERROR 1046 (3D000): No database selected

โš ๏ธ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์ „์—๋Š” use ๋ช…๋ น์–ด๋ฅผ ํ†ตํ•ด์„œ ์‚ฌ์šฉํ•  ๊ฒƒ์ž„์„ ๋ช…์‹œ์ ์œผ๋กœ ์•Œ๋ฆด ๊ฒƒ!

mysql> use {database};

ํ•˜์—ฌํŠผ ๊ทนํžˆ ์ดˆ๋ณด์ ์ธ ์‹ค์ˆ˜์˜€๋‹ค...

๊ฐ•ํ•œ ๊ฒฐํ•ฉ๊ณผ ์•ฝํ•œ ๊ฒฐํ•ฉ

1) ๊ฐ•ํ•œ ๊ฒฐํ•ฉ์˜ ์˜ˆ์‹œ

  1. Contoller๊ฐ€ Service ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉ

    public class Controller {
    	private final Service service;
    
    	public Controller() {
    		this.service = new Sevice();
    	}
    }
  2. Service๊ฐ€ Repostiroy ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉ

    public class Service {
    	private final Repository repository;
    
    	public Service() {
    		this.repository = new Repository();
    	}
    }
  3. ์ด๋Ÿฐ ์ƒํ™ฉ์—์„œ Repository ๊ฐ์ฒด๋ฅผ ์ƒ์„ฑํ•  ๋•Œ, DB ์ ‘์† ์‹œ ํ•„์š”ํ•œ id์™€ pw๋ฅผ ๋ฐ›์•„์„œ ์‚ฌ์šฉํ•œ๋‹ค๋ฉด...?

    public class Repository {
    
    	public Repository(String id, String pw) {
        	// DB ์—ฐ๊ฒฐ
        	Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/memo", id, pw);
    	}
    }

2) ๊ฐ•ํ•œ ๊ฒฐํ•ฉ์˜ ๋ฌธ์ œ์ 

์œ„์˜ ์ด๋ฏธ์ง€๋ฅผ ๋ณด์ž. Controller 5๊ฐœ๊ฐ€ ๊ฐ๊ฐ Service1 ์„ ์ƒ์„ฑํ•˜์—ฌ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋‹ค.

์ด ์ด๋ฏธ์ง€์— ๋”ฐ๋ฅด๋ฉด, Repository1 ์ƒ์„ฑ์ž ๋ณ€๊ฒฝ์— ์˜ํ•ด, ๋ชจ๋“  Contoller์™€ ๋ชจ๋“  Service์˜ ์ฝ”๋“œ ๋ณ€๊ฒฝ์ด ํ•„์š”ํ•ด์ง„๋‹ค.

3) ๊ฐ•ํ•œ ๊ฒฐํ•ฉ์„ ํ•ด๊ฒฐํ•˜๋ ค๋ฉด

  1. ๊ฐ ๊ฐ์ฒด์— ๋Œ€ํ•œ ๊ฐ์ฒด ์ƒ์„ฑ์€ ๋”ฑ 1๋ฒˆ๋งŒ!
  2. ์ƒ์„ฑ๋œ ๊ฐ์ฒด๋ฅผ ๋ชจ๋“  ๊ณณ์—์„œ ์žฌ์‚ฌ์šฉ!
  3. ์ƒ์„ฑ์ž ์ฃผ์ž…์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•„์š”๋กœํ•˜๋Š” ๊ฐ์ฒด์— ํ•ด๋‹น ๊ฐ์ฒด ์ฃผ์ž…!
โ–ถ ๋ณ€๊ฒฝ ์ „ (MemoController.java)
public class MemoController {

    private final MemoService memoService;

    public MemoController(MemoService memoService) {        
        this.memoService = new MemoService(jdbcTemplate);
    }
โ–ถ ๋ณ€๊ฒฝ ํ›„ (MemoController.java)
public class MemoController {

    private final MemoService memoService;

    public MemoController(MemoService memoService) {
        this.memoService = memoService;
    }

4) ๊ฒฐ๊ณผ์ ์œผ๋กœ...

  • Repository1 ์ƒ์„ฑ์ž ๋ณ€๊ฒฝ์€ ์ด์ œ ๋ˆ„๊ตฌ์—๊ฒŒ๋„ ์˜ํ–ฅ์„ ์ฃผ์ง€ ์•Š๊ฒŒ ๋˜์—ˆ๋‹ค.

  • Service1 ์ƒ์„ฑ์ž์— ๋ณ€๊ฒฝ์‚ฌํ•ญ์ด ์ƒ๊ฒจ๋„?
    ๋ชจ๋“  Contoller๋Š” ๋ณ€๊ฒฝํ•  ํ•„์š”๊ฐ€ ์—†์–ด์ง„๋‹ค.

  • ๊ฐ•ํ•œ ๊ฒฐํ•ฉ์—์„œ โ‡’ ๋Š์Šจํ•œ ๊ฒฐํ•ฉ์ด ๋˜์—ˆ๋‹ค.

์ฆ‰, ์ œ์–ด์˜ ํ๋ฆ„์ด ๋ฐ”๋€Œ์—ˆ๋‹ค๊ณ  ๋ณผ ์ˆ˜ ์žˆ๋‹ค!

profile
`ISFJ` T 49% F 51% /

0๊ฐœ์˜ ๋Œ“๊ธ€