https://johngrib.github.io/wiki/java-inner-class-may-be-static/ 종립님의 글을 참고하였습니다.
이거다!!!
public class MainCless{
class SubClass {
}
}
public class UserResponse {
/**
* 회원 정적 멤버 클래스
*/
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public static class UserDetailResponse {
private String email;
private String name;
private String phone;
private String birth;
private String roadAddress;
private String detailAddress;
private String bankName;
private String account;
@Builder
public UserDetailResponse(String email, String name, String phone,
String birth, String roadAddress, String detailAddress,
String bankName, String account) {
this.email = email;
this.name = name;
this.phone = phone;
this.birth = birth;
this.roadAddress = roadAddress;
this.detailAddress = detailAddress;
this.bankName = bankName;
this.account = account;
}
}
/**
* 회원 정적 멤버 클래스로 변환하여 리턴합니다.
* @param user 유저 엔티티
* @return 변환된 유저 상세조회 DTO
*/
public static UserDetailResponse toDetailUser(User user) {
return UserDetailResponse.builder()
.email(user.getEmail())
.name(user.getName())
.phone(user.getPhone())
.birth(user.getBirth())
.bankName(user.getBankName())
.account(user.getAccount())
.roadAddress(user.getUserAddress().getRoadAddress())
.detailAddress(user.getUserAddress().getDetailAddress())
.build();
}
}
------------------ 컨트롤러 --------------------
@GetMapping("/{userEmail}")
public UserResponse.UserDetailResponse getUser(@PathVariable("userEmail") String userEmail) {
User findUser = userService.getUser(userEmail);
return UserResponse.toDetailUser(findUser);
}