在QueryDSL中查询谓词

时间:2017-11-27 07:57:53

标签: java jpa spring-data querydsl

环境是Java,Spring-boot,Hibernat,QueryDSL,MySQL。

我有表结构

+----+-------------+--------
| id | address_id  | eventno
+----+-------------+--------
|  5 |         27  | F123
|  6 |         30  | F456
|  7 |         45  | F789
+----+-------------+--------

@Entity
public class Episode {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@NotEmpty
private String eventno;
@ManyToOne(cascade = CascadeType.ALL)
private Address address;

Episode_Person

+----+--------------+--------------+------------+-----------+
| id | episode_role | primary_flag | episode_id | person_id |
+----+--------------+--------------+------------+-----------+
| 19 | Buyer        |              |          5 |         1 |
| 20 | Subject      |              |          5 |         2 |
| 23 | Witness      |              |          6 |         3 |
| 24 | Child        |              |          6 |         4 |
| 27 | Buyer        |              |          5 |         3 |
| 63 | Investor     |              |          5 |         4 |
| 64 | Subject      |              |          7 |         1 |
| 65 | Subject      |              |          7 |         3 |

@Entity
public class EpisodePerson {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@Valid
private Person person;

@ManyToOne
private Episode episode;

+----+-----------+----------+
| id | firstname | surname  |
+----+-----------+----------+
|  1 | Clint     | eastwood |
|  2 | Angelina  | joilee   |
|  3 | Brad      | pitt     |
|  4 | Jennifer  | aniston  |

@Entity
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"nia"}))
public class Person {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private String surname;
private String firstname;
private String gender;

所以每集都有多个人。连接表是Episode_Person。

我的UI有一个数据表,每列都有一个过滤器:

enter image description here

过滤已经适用于事件和地址。在QueryDSL中看起来像这个谓词:

            BooleanBuilder where = new BooleanBuilder();
        if (pagination.getFilterBy().getMapOfFilters().get("eventno")!=null) {
            where.and(qEpisode.eventno.containsIgnoreCase(pagination.getFilterBy().getMapOfFilters().get("eventno")));
        }
        if (pagination.getFilterBy().getMapOfFilters().get("address")!=null) {
            where.and(qEpisode.address.formattedAddress.containsIgnoreCase(pagination.getFilterBy().getMapOfFilters().get("address")));
        }
        where.and(qEpisode.creatingUser.eq(user));
        List<Episode> e = episodeRepository.findAll(where);

我现在如何为案例名称添加第3个谓词,案例名称是根据一集中的人物集合中返回的前两个人构建的?

更新

为了澄清,支持UI视图的DTO包含&#34; casename&#34;属性。当Domain对象转换为DTO时,它在服务层中创建:

episodeDashboard.setNames(episodePersonList.get(0).getPerson().getSurname().toUpperCase() +" & " +episodePersonList.get(1).getPerson().getSurname().toUpperCase());

0 个答案:

没有答案