其他分享
首页 > 其他分享> > springJPA 之 QueryDSL(二)

springJPA 之 QueryDSL(二)

作者:互联网

具体实现如下:

@Override
public Paging<EmployeeSearchDto> listEmpsCorpId(EmpPageListRequest empPageListRequest) {

BooleanBuilder builder = new BooleanBuilder();
if(!StringUtils.isEmpty(empPageListRequest.getSearchTxt())){
builder.andAnyOf(
builder.or(EMPLOYEE.name.like('%'+empPageListRequest.getSearchTxt()+'%')),
builder.or(EMPLOYEE.jobNumber.like('%'+empPageListRequest.getSearchTxt()+'%')),
builder.or(USER.phone.like('%'+empPageListRequest.getSearchTxt()+'%'))
)
.and(EMPLOYEE.corpId.eq(empPageListRequest.getCorpId())
.and(EMPLOYEE.state.eq(EmployeeState.ENABLED)));
}
QueryResults<EmployeeSearchDto> employeeDtoQueryResults = jpqlQueryFactory.select(
Projections.bean(
EmployeeSearchDto.class,
EMPLOYEE.id,
EMPLOYEE.corpId,
EMPLOYEE.name,
USER.phone,
EMPLOYEE.jobNumber,
EMPLOYEE.position)).from(EMPLOYEE)
.leftJoin(USER).on(EMPLOYEE.userId.eq(USER.id))
.where(builder).offset(empPageListRequest.getPageNumber())
.limit(empPageListRequest.getPageSize()).fetchResults();
return Paging.convert(employeeDtoQueryResults,empPageListRequest.pageRequest(),empPageListRequest.getDtoClass());

标签:empPageListRequest,springJPA,builder,QueryDSL,getSearchTxt,USER,EMPLOYEE,eq
来源: https://www.cnblogs.com/zxy-come-on/p/14104836.html