使用spring和@querydsl predicate 时url中的查询语法

sqxo8psd  于 2021-07-13  发布在  Java
关注(0)|答案(0)|浏览(257)

如何编写http请求url以获得类似以下内容的查询:

select *
from incidents i,
     jira_issues ji
where i.incident_id = ji.incident_id
  and ji.external_jira_issue_id = 'ABC-123'
  and ji.jira_server_id = '1'

我有以下课程:

@Entity(name = "incidents")
public class IncidentEntity {
  @OneToMany(
      mappedBy = "incident",
      cascade = CascadeType.ALL
  )
  @LazyCollection(LazyCollectionOption.FALSE)
  private List<JiraIssueEntity> jiraIssues;
...
}
@Entity(name = "jira_issues")
public class JiraIssueEntity {

  @EmbeddedId
  @EqualsAndHashCode.Include
  private JiraIssueId id;

  @ManyToOne(fetch = FetchType.LAZY)
  @JoinColumn(name = "incident_id")
  @ToString.Exclude
  private IncidentEntity incident;
...
}
@Embeddable
public class JiraIssueId implements Serializable {

  @EqualsAndHashCode.Include
  private String externalJiraIssueId;
  @EqualsAndHashCode.Include
  private String jiraServerId;
}

这是我的api方法签名:

@GetMapping("")
  public Page<Incident> listIncidents(
      @QuerydslPredicate(root = IncidentEntity.class) Predicate predicate
  );

我知道我可以寄一些东西,比如:

/incidents/?jiraIssues.id.externalJiraIssueId=ABC-123&jiraIssues.id.jiraServerId=1"

这将转换为以下查询:

select *
from incidents incidenten0_
where (exists(select 1
              from jira_issues jiraissues1_
              where incidenten0_.incident_id = jiraissues1_.incident_id
                and (lower(jiraissues1_.external_jira_issue_id) like ? escape '!')))
  and (exists(select 1
              from jira_issues jiraissues2_
              where incidenten0_.incident_id = jiraissues2_.incident_id
                and (lower(jiraissues2_.jira_server_id) like ? escape '!')))

这不太好。
我不知道如何:
do equals和not contains(externaljiraissueid=-1234的行也将返回,但我不希望返回)。
检查相同的jiraissue是否有externaljiraissueid=-123和jiraissues.id.jiraserverid=1,并且没有不同的jiraissues,每个jiraissues都匹配一个(类似jiraissues.id=(-123,1)
谢谢您。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题