queryDsl分页查询加模糊查

        QCospProduct qCospProduct = QCospProduct.cospProduct;
        ArrayList<Predicate> listPredicate = new ArrayList<Predicate>();
        if(StringUtils.isNotEmpty(name)){
            Predicate predicate = qCospProduct.name.like("%!" + name + "%"+'!');
            listPredicate.add(predicate);
        }
        if(StringUtils.isNotEmpty(parentId)) {
            Predicate predicate = qCospProduct.typeId.eq(parentId);
            listPredicate.add(predicate);
        }
        Pageable pageable = PageRequest.of(page.intValue() - 1, size.intValue());

        return this.jpaQueryFactory.selectFrom(qCospProduct).where(ExpressionUtils.allOf(listPredicate)).offset(pageable.getOffset()).
                limit(pageable.getPageSize()).orderBy(qCospProduct.createTime.desc()).fetch();
    }

    @Override
    public long getCount(String name, String parentId) {
        QCospProduct qCospProduct = QCospProduct.cospProduct;
        ArrayList<Predicate> listPredicate = new ArrayList<Predicate>();
        if (org.apache.commons.lang3.StringUtils.isNotEmpty(name)) {
            Predicate predicate = qCospProduct.name.like("%" + name + "%");
            listPredicate.add(predicate);
        }
        if(StringUtils.isNotEmpty(parentId)) {
            Predicate predicate = qCospProduct.typeId.eq(parentId);
            listPredicate.add(predicate);
        }
        return this.jpaQueryFactory.selectFrom(qCospProduct).where(ExpressionUtils.allOf(listPredicate)).fetchCount();
    }

 @ApiOperation("分页查询")
    @GetMapping("/dim")
    public ResultBody dim(String parentId,String name, Integer page, Integer size) {
        try {
            List<CospProduct> list = cospProductService.page(parentId,name, page, size);
            long count = cospProductService.getCount(name,parentId);
            return ResultBody.success(new GridView(list, count));
        } catch (Exception e) {
            log.error("查询失败",e);
            return ResultBody.failure("查询失败");
        }
    }
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.meritdata.cloud.base.mvc.entity;

import java.util.List;

public class GridView<T> {
    private List<T> rows;
    private long total;
    private int pageSize;
    private int pageNumber;
    private int totalPages;
    private int records;

    public List<T> getRows() {
        return this.rows;
    }

    public void setRows(List<T> rows) {
        this.rows = rows;
    }

    public long getTotal() {
        return this.total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public int getPageSize() {
        return this.pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageNumber() {
        return this.pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public int getTotalPages() {
        return this.totalPages;
    }

    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }

    public int getRecords() {
        return this.records;
    }

    public void setRecords(int records) {
        this.records = records;
    }

    public GridView() {
    }

    public GridView(List<T> rows, long total) {
        this.setRows(rows);
        this.setTotal(total);
    }

    public GridView(List<T> rows, long total, int pageSize, int PageNumber) {
        this.setRows(rows);
        this.setTotal(total);
        this.setPageSize(pageSize);
        this.setPageNumber(PageNumber);
        int totalPages = (int)(total / (long)pageSize);
        if (total % (long)pageSize > 0L) {
            this.setTotalPages(totalPages + 1);
        } else {
            this.setTotalPages(totalPages);
        }

    }

    public GridView(List<T> rows, long total, int records, int pageSize, int PageNumber) {
        this.setRows(rows);
        this.setRecords(records);
        this.setPageSize(pageSize);
        this.setPageNumber(PageNumber);
        int totalPages = (int)(total / (long)pageSize);
        if (total % (long)pageSize > 0L) {
            this.setTotal((long)(totalPages + 1));
        } else {
            this.setTotal((long)totalPages);
        }

    }
}

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.meritdata.cloud.resultmodel;

import com.meritdata.cloud.base.DisableEncrypt;
import java.io.PrintWriter;
import java.io.Serializable;
import java.io.StringWriter;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

@DisableEncrypt
public class ResultBody<T> implements Serializable {
    private static final long serialVersionUID = -3948389268046368059L;
    private Date timestamp = new Date();
    private Integer status;
    private String error;
    private String message;
    private String stackmessage;
    private String path;
    private T data;
    private Map<String, String> extraInfo = new HashMap();
    private boolean success;

    public ResultBody() {
    }

    public Date getTimestamp() {
        return this.timestamp;
    }

    public static long getSerialVersionUID() {
        return -3948389268046368059L;
    }

    public String getPath() {
        HttpServletRequest request = ((ServletRequestAttributes)((ServletRequestAttributes)RequestContextHolder.currentRequestAttributes())).getRequest();
        return request.getRequestURI().toString();
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getStatus() {
        return this.status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getMessage() {
        return this.message != null ? this.message : ResultStatus.getMessage(this.status);
    }

    public boolean isSuccess() {
        return this.success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getStackmessage() {
        try {
            if (this.stackmessage != null) {
                String var1 = this.stackmessage;
            }
        } catch (Exception var5) {
            var5.printStackTrace();
        } finally {
            return this.stackmessage;
        }
    }

    public void setStackmessage(String stackmessage) {
        this.stackmessage = stackmessage;
    }

    public void addExtraInfo(String key, String value) {
        this.extraInfo.put(key, value);
    }

    public Map<String, String> getExtraInfo() {
        return this.extraInfo;
    }

    public static ResultBody success() {
        ResultBody result = new ResultBody();
        result.setResultStatus(ResultStatus.SUCCESS);
        result.setSuccess(true);
        return result;
    }

    public static ResultBody success(Object data) {
        ResultBody result = new ResultBody();
        result.setResultStatus(ResultStatus.SUCCESS);
        result.setData(data);
        result.setSuccess(true);
        return result;
    }

    public static ResultBody failure(String message) {
        ResultBody result = new ResultBody();
        result.setResultStatus(ResultStatus.FAILURE);
        result.setMessage(message);
        result.setSuccess(false);
        return result;
    }

    public static ResultBody failure(ResultStatus resultCode) {
        ResultBody result = new ResultBody();
        result.setResultStatus(resultCode);
        result.setSuccess(false);
        return result;
    }

    public static ResultBody failure(ResultStatus resultCode, Throwable e) {
        ResultBody result = new ResultBody();
        result.setResultStatus(resultCode);
        result.setStackmessage(getStackTrace(e));
        result.setMessage(e.getMessage());
        result.setSuccess(false);
        return result;
    }

    public static ResultBody failure(ResultStatus resultStatus, Object data) {
        ResultBody result = new ResultBody();
        result.setResultStatus(resultStatus);
        result.setData(data);
        result.setSuccess(false);
        return result;
    }

    public static ResultBody failure(Integer status, String message, Object data, Throwable e) {
        ResultBody result = new ResultBody();
        result.setStatus(status);
        result.setMessage(message);
        result.setData(data);
        result.setStackmessage(getStackTrace(e));
        result.setSuccess(false);
        return result;
    }

    public void setResultStatus(ResultStatus resultStatus) {
        this.status = resultStatus.status();
        this.message = resultStatus.message();
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public static String getStackTrace(Throwable t) {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);

        String var3;
        try {
            if (t != null) {
                t.printStackTrace(pw);
                var3 = sw.toString();
                return var3;
            }

            var3 = "";
        } finally {
            pw.close();
        }

        return var3;
    }
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值