public class OrdererSpec implements Specification<Order> {
private String orderer;
public OrdererSpec(String orderer) {
this.orderer = orderer;
}
@Override
public Predicate toPredicate(Root<Order> root, CriteriaBuilder cb) {
return cb.equal(root.get("orderer").get("name"), orderer);
}
}
조회 방법
List<Order> orders = orderRepository.findAll(new OrdererSpec("madvirus"));
Sort sort = Sort.by(Order_.orderDate).descending();
List<Order> orders = orderRepository.findAll(sort);
Pageable pageable = Pageable.of(0, 3);
Page<Order> orders = orderRepository.findAll(pageable)
@Entity
public class Order {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String customer;
@Subselect(query = "SELECT c FROM Customer c WHERE c.name = :customer", resultClass = Customer.class)
private Customer customerDetails;
}