弹簧数据 - 存储库方法名称中的 OR 条件
2022-09-02 10:47:11
在我的Spring Data项目中,我有一个以下实体:
@Entity
@NamedEntityGraph(name = "graph.CardPair", attributeNodes = {})
@Table(name = "card_pairs")
public class CardPair extends BaseEntity implements Serializable {
private static final long serialVersionUID = 7571004010972840728L;
@Id
@SequenceGenerator(name = "card_pairs_id_seq", sequenceName = "card_pairs_id_seq", allocationSize = 1)
@GeneratedValue(strategy = GenerationType.AUTO, generator = "card_pairs_id_seq")
private Long id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "card1_id")
private Card card1;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "card2_id")
private Card card2;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "selected_card_id")
private Card selectedCard;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "board_id")
private Board board;
....
}
我需要实现一个Spring Data存储库方法,该方法将查找基于,和。对我来说更复杂的情况是,因为我需要构造一个条件,其中CardPair
cardPairId
board
card
Card
card1 = card or card2 = card
是否可以通过Spring Data存储库方法名称提供此条件?
例如
cardPairRepository.findByIdAndBoardAnd[card1 = card or card2 = card]AndSelectedCardIsNull(cardPairId, board, card);
是否可以将此条件转换为方法名称?card1 = card or card2 = card