[英]Spring Data JPA filtering
I have a controller which is like below. 我有一个像下面的控制器。
public String getAccountsFilter(
@PathVariable("cardHolderId") String cardHolderId,
@RequestParam(value = "accountType", required = false) String accountType,
@RequestParam(value = "name", required = false) String name)
The AccountEntity is as below AccountEntity如下
public class AccountEntity implements Serializable {
private static final long serialVersionUID = 1L;
private String id;
private String accounttype;
private Date endDate;
private boolean active;
private PlanEntity planEntity;
private Set<TransactionEntryEntity> transactionEntry = new HashSet<TransactionEntryEntity>();
I did the filtering for id
and accountType
which is easy using findByIdAndAccountType()
method, and the query is generated automatically. 我为过滤
id
和accountType
其易于使用findByIdAndAccountType()
方法,并自动生成查询。
But if i want to filter using id
and name
which is property of Plan (AccountEntity.PlanEntity.name)
, it is not straightforward since name
is from the child table. 但是,如果我想使用
id
和name
进行过滤,这是Plan (AccountEntity.PlanEntity.name)
属性Plan (AccountEntity.PlanEntity.name)
,这不是Plan (AccountEntity.PlanEntity.name)
容易的事,因为name
来自子表。 How can i approach for this criteria? 我该如何达到这个标准?
Assume PlanEntity and TransactionEntryEntity is being annotated by @OneToOne or @OneToMany etc 假设正在通过@OneToOne或@OneToMany等对PlanEntity和TransactionEntryEntity进行注释
You may do the following in one of the method in the repository of AccountEntity 您可以在AccountEntity信息库中的一种方法中执行以下操作
@Query("select a from AccountEntity a where a.planEntity.name = :name")
public aMethod( @Param("name") String name)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.