嗨,我正在使用查询方法来获取我的结果。我的应用程序的设计如下。
成员实体
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Getter
@ToString
public class Member {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long mno;
private String name;
private String phone;
}
memberimage实体
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
@ToString(exclude="member")
public class MemberImage {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long inum;
private String uuid;
private String imgName;
private String path;
@ManyToOne(fetch=FetchType.LAZY)
private Member member;
}
以及我正在使用的查询方法
memberrepository.java文件
@Query("select m, mi, count(mi) from Member m"+ " left outer join MemberImage mi on mi.member=m group by m")
Page<Object[]> getListPage(Pageable pageable);
pagerequestdto.java页面
@Builder
@AllArgsConstructor
@Data
public class PageRequestDTO {
private int page;
private int size;
private String type;
private String keyword;
public PageRequestDTO(){
this.page = 1;
this.size = 10;
}
public Pageable getPageable(Sort sort){
return PageRequest.of(page -1, size, sort);
}
}
我试着用booleanbuilder做一个搜索操作,如下所示
private BooleanBuilder getSearch(PageRequestDTO requestDTO){
String type = requestDTO.getType();
BooleanBuilder booleanBuilder = new BooleanBuilder();
String keyword = requestDTO.getKeyword();
BooleanExpression expression = qMember.mno.gt(0L);
booleanBuilder.and(expression);
if(type == null || type.trim().length() == 0){
return booleanBuilder;
}
BooleanBuilder conditionBuilder = new BooleanBuilder();
if(type.contains("n")){
conditionBuilder.or(qMember.name.contains(keyword));
}
if(type.contains("p")){
conditionBuilder.or(qMember.phone.contains(keyword));
}
booleanBuilder.and(conditionBuilder);
return booleanBuilder;
}
我想要page<object[]>的结果和我编写的booleanbuilder的术语。有什么办法得到这个结果吗?我尝试了memberrepository.getlistpage(booleanbuilder,pageable)并查看是否可以得到正确的结果,但是没有。有什么建议吗?
暂无答案!
目前还没有任何答案,快来回答吧!