Sokwon Spring Lv2 #30
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
공부한 내용
Q. Controller는 뭘까요?
자바 스프링 MVC 3요소 중 하나인 Controller는 클라이언트의 1)요청을 받아 2)기능을 수행 후 3) 사전에 정의한 형태로 반환합니다.
스프링에서 자주 사용한는 두가지 Controller:
@Controller: 스프링에서 프론트엔드까지 담당하는 경우, View를 통해 화면을 렌더링 후 반환합니다.@RestController: 스프링에서 API만 담당하는 경우, 정의한 데이터 형식으로 Response를 반환합니다.Q. Controller는 왜 인터페이스가 없어도 될까요?
Controller는 인터페이스를 구현함으로써 얻는 이익이 적습니다.
Q. Service는 뭘까요?
자바 스프링에서 Service는 비즈니스 로직을 담당하는 계층입니다.
Q. Repository는 뭘까요?
자바 스프링에서 Repository는 데이터베이스를 추상화하기 위한 인터페이스/클래스입니다.
Q. Entity가 뭘까요?
Entity의 사전적 의미는 개념이나 정보 단위와 같은 현실 세계의 개체입니다. 하나 이상의 속성을 가질 수 있습니다.
자바 스프링에서 Entity는 데이터베이스에서 지속될 수있는 데이터를 나타내는 POJO(Plain Old Java Object)입니다.
Q. DTO가 뭘까요?
DTO(Data Transfer Object)는 계층 간 주고받는 데이터 형태의 약속입니다.
DTO의 기능
toEntity(), static factory 메서드 등 제공하는 경우도 있음.Best Practice
User,UserDto).UserCreationDto,UserResponseDto,UserUpdateDto등 용도별로 분리 가능.@NotNull,@Min,@Size등 Bean Validation으로 입력값을 사전에 검증.@Valid로 처리 후, Service로 넘김.toEntity(), “Entity:toDto()”)으로 충분.UserDetailResponse)와 “생성/수정 요청” DTO(UserRequest)를 나누면 관리가 쉽고 안전함.Anti-Pattern