Skip to content

Conversation

@s-chan-o
Copy link

๐Ÿ’ก ๊ฐœ์š”

  • ๋งˆ์ธ๋“œ์›จ์ด 4๊ณผ์ œ ์ˆ˜ํ–‰

๐Ÿ“ƒ ์ž‘์—…๋‚ด์šฉ

  • CRUD๊ธฐ๋Šฅ์„ ๊ฐ€์ง„ Board๊ตฌํ˜„

๐Ÿ”€ ๋ณ€๊ฒฝ์‚ฌํ•ญ

๐Ÿ™‹โ€โ™‚๏ธ ์งˆ๋ฌธ์‚ฌํ•ญ

๐Ÿ’€ ์–ด๋ ค์› ๋˜ ์ 

public class BoardResponseDto {
private String title;
private String content;
private LocalDateTime createdAt;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ž‘์„ฑ๋œ ์‹œ๊ฐ„๊ณผ ์ˆ˜์ •๋œ ์‹œ๊ฐ„์„ ๋ฐ˜ํ™˜ํ•˜๋Š” Board entity์—๋Š” ์ด๋Ÿฐ ํ•„๋“œ๊ฐ€ ์—†์–ด์š” ๋ฌด์Šจ ์‹œ๊ฐ„์„ ๋ฐ˜ํ™˜ํ•˜์‹œ๋Š”๊ฑด๊ฐ€์š”?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์‹œ๊ฐ„์— ๊ด€ํ•œ ํ•„๋“œ๋ฅผ ์ƒ์„ฑํ•˜๋ ค๊ณ  ํ–ˆ์—ˆ๋Š”๋ฐ ์‚ญ์ œ๋ฅผ ์•ˆํ–ˆ๋˜๊ฒƒ ๊ฐ™์Šต๋‹ˆ๋‹ค.
050af7d


private final BoardService boardService;

@Autowired
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Autowired๋ฅผ ์‚ฌ์šฉํ•œ ์ƒ์„ฑ์ž ์ฃผ์ž…๋ณด๋‹ค @RequiredArgsConstructor๋ฅผ ์‚ฌ์šฉํ•œ ์ƒ์„ฑ์ž ์ฃผ์ž… ๋ฐฉ๋ฒ•๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒŒ ์ข‹์„ ๊ฒƒ๊ฐ™์•„์š”

@Autowird์„ ํ™œ์šฉํ•œ ์ƒ์ •์ž ์ฃผ์ž…์€ ํ•„๋“œ ์ฃผ์ž…์ด๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค
ํ•„๋“œ ์ฃผ์ž… ๋ฐฉ๋ฒ•์€ ๋งค์šฐ ๊ฐ„๋‹จํ•ด์„œ ํŽธ๋ฆฌํ•˜์ง€๋งŒ ์ด๋Ÿฌํ•œ ๋ฐฉ๋ฒ•๋ง๊ณ ๋Š” ์žฅ์ ์ด ์—†์–ด ์Šคํ”„๋ง 4.3๋ถ€ํ„ฐ๋Š” ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ae66a75
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

this.boardService = boardService;
}
//๊ธ€ ๋“ฑ๋ก
@PostMapping("/boards")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ณตํ†ต์ ์ธ url์€ @RequestMapping ํ†ตํ•ด ํ•œ๋ฒˆ๋งŒ ์ ๊ณ ๋„ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์–ด์š”

@RequestMapping์€ ํด๋ž˜์Šค์™€ ๋ฉ”์„œ๋“œ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์ง€๋งŒ ์œ„์น˜์— ๋”ฐ๋ผ ์˜๋ฏธ๊ฐ€ ๋‹ค๋ฅด๋‹ˆ ์ฐพ์•„๋ณด๊ณ  ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

007626e
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ์™„๋ฃŒํ–ˆ์Šต๋‹ˆ๋‹ค

@@ -0,0 +1,6 @@

spring.datasource.url=jdbc:mysql://localhost:3307/mindwaytest?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋งŽ์€ ํ”„๋กœ์ ํŠธ์—์„œ application.properties ํŒŒ์ผ๋ณด๋‹ค application.ymlํŒŒ์ผ์ด ๊ฐ€๋…์„ฑ์ด ๋” ์ข‹๊ณ  ์‚ฌ์šฉ์ž ์นœํ™”์ ์ด์–ด์„œ yml ํŒŒ์ผ ๋” ๋งŽ์ด ์‚ฌ์šฉํ•ด์š”
๊ทธ๋ž˜์„œ yml ํŒŒ์ผ ์‚ฌ์šฉํ•ด๋ณด๋Š”๊ฒƒ๋„ ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

8abe05e
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

@@ -0,0 +1,6 @@

spring.datasource.url=jdbc:mysql://localhost:3307/mindwaytest?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true
spring.datasource.username=root
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

username์ด๋‚˜ password ๊ฐ™์€ ๋ฏผ๊ฐํ•œ ์ •๋ณด๋Š” ์™ธ๋ถ€์— ๋…ธ์ถœ๋˜๋ฉด ์•ˆ๋˜๊ธฐ ๋•Œ๋ฌธ์— ์ปค๋ฐ‹์„ ํ• ๋•Œ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ฒ˜๋ฆฌํ•ด์„œ ์˜ฌ๋ ค์ฃผ์„ธ์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ecca6f6
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

}
//๋ชจ๋“  ๊ธ€ ๊ฐ€์ ธ์˜ค๊ธฐ
public List<BoardListResponseDto> findAllBoard(){
try{
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-catch ๋ฌธ์„ ์‚ฌ์šฉํ•˜์‹  ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”??

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ฝ”๋“œ ์‹คํ–‰ ์ค‘ ๋ฐœ์ƒํ•  ์˜ˆ์™ธ ์ฒ˜๋ฆฌ๋ฅผ ์œ„ํ•ด ์‚ฌ์šฉํ•˜๊ณ  ์žˆ์Šต๋‹ˆ๋‹ค

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

try-catch ๊ตฌ๋ฌธ์„ ์‚ฌ์šฉํ•ด์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค Optional๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒŒ ๋” ์ข‹์„ ๊ฒƒ ๊ฐ™์•„์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cd2e132
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ˆ์™ธ์ฒ˜๋ฆฌ Optionl ์‚ฌ์šฉํ•ด์„œ ์ž˜ ํ•ด์ค€๊ฑฐ ๊ฐ™์€๋ฐ ์ „์ฒด ๊ธ€์„ ๋ถˆ๋Ÿฌ์˜ค๋Š” ์ƒํ™ฉ์—์„œ ์˜ˆ์™ธ์ฒ˜๋ฆฌ๊ฐ€ ํ•„์š”ํ•ด๋ณด์ด์ง€ ์•Š์•„์š” ๊ตณ์ด ์ˆ˜์ •ํ•  ํ•„์š”๋Š” ์—†์ง€๋งŒ ๋‹ค์Œ์— ๊ฐœ๋ฐœํ•  ๋•Œ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”!

//์ „์ฒด ๋ชฉ๋ก ์กฐํšŒ
@GetMapping("/boards")
public List<BoardListResponseDto> getAllBoards(){
return boardService.findAllBoard();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์ปจํŠธ๋กค๋Ÿฌ์—์„œ ๋ฐ˜ํ™˜ํ• ๋•Œ ResponseEntity ์‚ฌ์šฉํ•ด์„œ ๋ฐ˜ํ™˜๊ฐ’๊ณผ ์ƒํƒœ ์ฝ”๋“œ๋ฅผ ํ•จ๊ป˜ ๋ฐ˜ํ™˜ํ•˜๋ฉด ์ข‹์„๊ฑฐ ๊ฐ™์•„์š”

ResponseEntity๋Š” ์ ์ ˆํ•œ ์ƒํƒœ ์ฝ”๋“œ์™€ ์‘๋‹ต ํ—ค๋” ๋ฐ ์‘๋‹ต ๋ณธ๋ฌธ์„ ์ƒ์„ฑํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ์— ์ „๋‹ฌํ•˜๊ธฐ ์œ„ํ•ด ์‚ฌ์šฉํ•ฉ๋‹ˆ๋‹ค

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

c3af8d1
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ResponseEntity๋ฅผ ์‚ฌ์šฉํ•ด์„œ return ํ• ๋•Œ๋Š” ์ƒ์„ฑ์ž๋ณด๋‹ค Builer ํŒจํ„ด์„ ์‚ฌ์šฉํ•ด์š”

์ƒ์„ฑ์ž๋ณด๋‹ค Builder ํŒจํ„ด์„ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด ์œ ์ง€๋ณด์ˆ˜์— ์ข‹๊ณ  ์˜๋ฏธ๊ฐ€ ์ง๊ด€์ ์ž„

private LocalDateTime createdAt;
private LocalDateTime modifiedAt;
//Entity -> dto
public BoardListResponseDto(Board board){
Copy link

@ta2ye0n ta2ye0n Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

entity์—์„œ dto ๋ณ€ํ™˜ํ•˜๋Š” ๋ฉ”์„œ๋“œ๊ฐ€ ๋‘๊ฐœ ์žˆ๋Š”๋ฐ ๋‘ ๋ฉ”์„œ๋“œ๊ฐ€ title๋ฅผ ๊ฐ€์ ธ์˜ค๋Š” ๋‚ด์šฉ์œผ๋กœ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ํ•˜๋Š” ๋ฉ”์„œ๋“œ๊ฐ™์€๋ฐ ๋‘๊ฐœ๋ฅผ ๋งŒ๋“œ์‹  ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”??

์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š” ๋ฉ”์„œ๋“œ๋Š” ์ง€์šฐ๋Š”๊ฒŒ ์ข‹์„๊ฒƒ๊ฐ™์•„์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

177f1fb
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

Copy link

@ta2ye0n ta2ye0n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๊ธ€ ์ž‘์„ฑ๊ณผ ๊ธ€ ์ˆ˜์ •ํ•  ๋•Œ ๊ฐ™์€ dto๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ ๋ถ„๋ฆฌํ•ด์ฃผ์„ธ์š”

ex) ๊ธ€์ž‘์„ฑ -> BoardWriteRequestDto ๊ธ€์ˆ˜์ • -> BoardUpdateRequestDto (์ด๊ฑด ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”)

import lombok.*;

@NoArgsConstructor
@Entity(name = "users")
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

board์— ๊ด€๋ จ๋œ entity์ธ๋ฐ users๋กœ ์ €์žฅ ํ•˜๋Š”๊ฑด ๋งž์ง€ ์•Š๋Š” ๊ฒƒ ๊ฐ™์•„ ๋ณด์—ฌ์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6536bf5
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

@AllArgsConstructor
public class BoardService {

private final BoardRepository boardRepository;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@AllArgsConstructor๋ฅผ ์‚ฌ์šฉํ•ด๋„ ๋ฌธ์ œ๋Š” ์—†์œผ๋‚˜ ํ•„๋“œ์— final์ด ๋ถ™์–ด์„œ @AllArgsConstructor๋Œ€์‹ ์— @RequiredArgsConstructor๋ฅผ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด ๋” ์ ์ ˆํ•ฉ๋‹ˆ๋‹ค
์ƒ์„ฑ์ž ์–ด๋…ธํ…Œ์ด์…˜์— ๋Œ€ํ•ด ์•Œ์•„๋ณด์‹œ๋ฉด ๋„์›€์ด ๋ ๊ฑฐ ๊ฐ™์Šต๋‹ˆ๋‹ค

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.
c8be7a6

@@ -1,8 +1,8 @@
spring:
datasource:
url: jdbc:mysql://localhost:3307/mindwaytest?serverTimezone=Asia/Seoul&useSSL=false&allowPublicKeyRetrieval=true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url ๋ถ€๋ถ„๋„ ํ™˜๊ฒฝ ๋ณ€์ˆ˜ ์ฒ˜๋ฆฌ ํ•ด์ฃผ์„ธ์š”

ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ฒ˜๋ฆฌ๋Š” {$USERNAME} ์ด๋Ÿฐ์‹์œผ๋กœ ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

์˜ค๋ฅ˜ ์ˆ˜์ • ํ–ˆ์Šต๋‹ˆ๋‹ค.
247e5c8

Copy link

@ta2ye0n ta2ye0n Jul 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

url ๋ถ€๋ถ„์ด ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ฒ˜๋ฆฌ๊ฐ€ ๋˜์ง€ ์•Š์•˜์–ด์š” ๋‹ค์‹œ ํ™•์ธํ•˜๊ณ  ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์ฒ˜๋ฆฌํ•ด์ฃผ์„ธ์š”

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

๋‹ค์‹œ ํ™•์ธํ–ˆ์Šต๋‹ˆ๋‹ค. ์ฃ„์†กํ•ฉ๋‹ˆ๋‹ค.
ffba8af

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ํ–ˆ์Šต๋‹ˆ๋‹ค ๊ฐ์‚ฌํ•ฉ๋‹ˆ๋‹ค!
0dacb5e

@s-chan-o
Copy link
Author

๊ธ€ ์ž‘์„ฑ๊ณผ ๊ธ€ ์ˆ˜์ •ํ•  ๋•Œ ๊ฐ™์€ dto๋ฅผ ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š”๋ฐ ๋ถ„๋ฆฌํ•ด์ฃผ์„ธ์š”

ex) ๊ธ€์ž‘์„ฑ -> BoardWriteRequestDto ๊ธ€์ˆ˜์ • -> BoardUpdateRequestDto (์ด๊ฑด ์˜ˆ์‹œ์ž…๋‹ˆ๋‹ค ์ฐธ๊ณ ํ•ด์„œ ์ˆ˜์ •ํ•ด์ฃผ์„ธ์š”)

820fb3a
ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ ํ–ˆ์Šต๋‹ˆ๋‹ค.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants