jpashop : 컬렉션 조회 v3 (dto 응답, fetch join, distinct)
This commit is contained in:
@@ -36,4 +36,12 @@ public class OrderApiController {
|
||||
.map(OrderDto::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@GetMapping("/api/v3/orders")
|
||||
public List<OrderDto> ordersV3() {
|
||||
List<Order> orders = orderRepository.findAllWithItem();
|
||||
return orders.stream()
|
||||
.map(OrderDto::new)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,4 +103,14 @@ public class OrderRepository {
|
||||
" join fetch o.delivery", Order.class)
|
||||
.getResultList();
|
||||
}
|
||||
|
||||
public List<Order> findAllWithItem() {
|
||||
return em.createQuery(
|
||||
"select distinct o from Order o" +
|
||||
" join fetch o.member m" +
|
||||
" join fetch o.delivery d" +
|
||||
" join fetch o.orderItems oi" +
|
||||
" join fetch oi.item i", Order.class)
|
||||
.getResultList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user