inflearn logo
강의

講義

知識共有

本当! Spring BootとJPAの活用2 - API開発とパフォーマンスの最適化

注文照会V6:JPAからDTOへの直接照会、フラットデータ最適化

선생님 v6에서 groupingBy에 o객체를 참조 못합니다..ㅠㅠ

667

boki

投稿した質問数 31

0

# OrderQueryDto

@Data
public class OrderQueryDto {

private Long orderId;
private String name;
private LocalDateTime orderDate;
private OrderStatus orderStatus;
private Address address;
private List<OrderItemQueryDto> orderItems;

public OrderQueryDto(Long orderId, String name, LocalDateTime orderDate, OrderStatus orderStatus, Address address) {
this.orderId = orderId;
this.name = name;
this.orderDate = orderDate;
this.orderStatus = orderStatus;
this.address = address;
}

public OrderQueryDto(Long orderId, String name, LocalDateTime orderDate, OrderStatus orderStatus, Address address, List<OrderItemQueryDto> orderItems) {
this.orderId = orderId;
this.name = name;
this.orderDate = orderDate;
this.orderStatus = orderStatus;
this.address = address;
this.orderItems = orderItems;
}
}

# OrderFlatDto

@Data
public class OrderFlatDto {

private Long orderId;
private String name;
private LocalDateTime orderDate; //주문시간
private Address address;
private OrderStatus orderStatus;

private String itemName;//상품 명
private int orderPrice; //주문 가격
private int count; //주문 수량

public OrderFlatDto(Long orderId, String name, LocalDateTime orderDate, OrderStatus orderStatus, Address address, String itemName, int orderPrice, int count) {
this.orderId = orderId;
this.name = name;
this.orderDate = orderDate;
this.orderStatus = orderStatus;
this.address = address;
this.itemName = itemName;
this.orderPrice = orderPrice;
this.count = count;
}
}

# Tried to fix...

JPA spring-boot spring java

回答 3

0

yh

안녕하세요. km54277님

먼저 질문을 새로 올려주세요. 그리고 해당 질문에

전체 프로젝트를 압축해서 구글 드라이브로 공유해서 링크를 남겨주세요.

추가로 다음 내용도 코멘트 부탁드립니다.

1. 실행 방법을 알려주세요.

2. 어떻게 문제를 확인할 수 있는지 자세한 설명을 남겨주세요.

감사합니다.

0

km54277

저도 현재 같은 에러가 발생하고 있는데 선생님께서 올려주신 코드 그대로 넣어도 오류가 발생합니다..

0

yh

안녕하세요. 보키님

다음 코드를 복사해주세요^^

괄호 하나라도 틀리면 안됩니다^^!

@GetMapping("/api/v6/orders")
public List<OrderQueryDto> ordersV6() {
List<OrderFlatDto> flats = orderQueryRepository.findAllByDto_flat();

return flats.stream()
.collect(groupingBy(o -> new OrderQueryDto(o.getOrderId(), o.getName(), o.getOrderDate(), o.getOrderStatus(), o.getAddress()),
mapping(o -> new OrderItemQueryDto(o.getOrderId(), o.getItemName(), o.getOrderPrice(), o.getCount()), toList())
)).entrySet().stream()
.map(e -> new OrderQueryDto(e.getKey().getOrderId(), e.getKey().getName(), e.getKey().getOrderDate(), e.getKey().getOrderStatus(), e.getKey().getAddress(), e.getValue()))
.collect(toList());
}

강의 관련 외 질문입니다.

0

68

2

SpringBoot4 + Hibernate7 모듈 등록 방법 공유

0

92

1

BeanCreationException

0

91

3

Update 후 UpdateMemberResponse 매핑할 때

0

50

1

트랜잭션을 사용 안 할 때 커넥션은 언제 가져오나요?

0

101

2

페이징 + 검색조건 관련해서 질문드립니다.

0

70

1

Query Dsl Q파일 질문입니다.

0

84

1

루트 쿼리라는것은

0

60

1

메서드를 분리하는 기준

0

65

1

findAllWithMemberDelivery 메서드 질문드립니다.

0

111

3

연관관계 매핑을 안 쓸 경우, 사용해야 하는 전략

0

86

2

fetch join과 영속화와 OSIV의 관계

0

87

2

Distinct 사용 전 결과에 대한 의문

0

117

2

레포지토리 계층에서의 트랜잭션에 대한 의문

0

59

1

영속성 컨텍스트 생명주기의 신기한 부분이 있습니다.

0

78

2

dto 필드 속 엔티티 여부

0

60

1

뷰템플릿 사용 시

0

77

2

Result 클래스 관련 질문

0

56

1

@PostConstruct 프록시 관련 질문드립니다

0

86

1

DTO 대신 Form 사용은 안되나요?

0

138

1

OSIV ON 상태일 때

0

96

1

fetch join VS fetch join 페이징 궁금증

0

187

2

양방향 연관관계 알아보는 법?

0

106

1

16강 17강 간단 정리 이게 맞을까요 ?

0

166

2