All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.aly8246.collectionutil.util.Page Maven / Gradle / Ivy

Go to download

Collection Util is a mybatis plug-in designed to solve the problem of N + 1 in mysql. When you use Mysql to query linked tables and pages, there will be n + 1 problem. This plug-in can help you!

The newest version!
package com.github.aly8246.collectionutil.util;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.ToString;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;

import java.util.Collections;
import java.util.List;


/**
 * Mybatis plus 的Page类,用于接收mp风格的分页参数
 *
 * @author 南有乔木
 * @version v.1.0.2
 * @see Page
 */
@ApiModel
@Slf4j
@ToString(callSuper = true)
public class Page implements IPage {
    private static final long serialVersionUID = 8545996863226528798L;

    @ApiModelProperty("记录")
    private List records;

    @ApiModelProperty(value = "总数", example = "1", required = true)
    private Long total;

    @ApiModelProperty(value = "页大小", example = "10")
    private Long size;

    @ApiModelProperty(value = "当前页", example = "1", required = true)
    private Long current;
    private String[] ascs;
    private String[] descs;

    private Boolean optimizeCountSql;

    @ApiModelProperty(value = "是否搜索数量", example = "true", required = true)
    private Boolean searchCount;

    public Page() {
        this.records = Collections.emptyList();
        this.total = 0L;
        this.size = 10L;
        this.current = 1L;
        this.optimizeCountSql = true;
        this.searchCount = true;
    }

    public Page(long current, long size) {
        this(current, size, 0L);
    }

    public Page(long current, long size, long total) {
        this(current, size, total, true);
    }

    public Page(long current, long size, boolean isSearchCount) {
        this(current, size, 0L, isSearchCount);
    }

    public Page(long current, long size, long total, boolean searchCount) {
        this.records = Collections.emptyList();
        this.total = 0L;
        this.size = 10L;
        this.current = 1L;
        this.optimizeCountSql = true;
        this.searchCount = true;
        if (current > 1L) {
            this.current = current;
        }

        this.size = size;
        this.total = total;
        this.searchCount = searchCount;
    }

    public boolean hasPrevious() {
        return this.current > 1L;
    }

    public boolean hasNext() {
        return this.current < this.getPages();
    }

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

    public Page setRecords(List records) {
        this.records = records;
        return this;
    }

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

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

    public long getSize() {
        return this.size;
    }

    public Page setSize(long size) {
        this.size = size;
        return this;
    }

    public long getCurrent() {
        return this.current;
    }

    public Page setCurrent(long current) {
        this.current = current;
        return this;
    }

    public String[] ascs() {
        return this.ascs;
    }

    public Page setAscs(List ascs) {
        if (!CollectionUtils.isEmpty(ascs)) {
            this.ascs = (String[]) ascs.toArray(new String[0]);
        }

        return this;
    }

    public Page setAsc(String... ascs) {
        this.ascs = ascs;
        return this;
    }

    public String[] descs() {
        return this.descs;
    }

    public Page setDescs(List descs) {
        if (!CollectionUtils.isEmpty(descs)) {
            this.descs = (String[]) descs.toArray(new String[0]);
        }

        return this;
    }

    public Page setDesc(String... descs) {
        this.descs = descs;
        return this;
    }

    public boolean optimizeCountSql() {
        return this.optimizeCountSql;
    }

    public boolean isSearchCount() {
        return this.total < 0L ? false : this.searchCount;
    }

    public Page setSearchCount(boolean searchCount) {
        this.searchCount = searchCount;
        return this;
    }

    public Page setOptimizeCountSql(boolean optimizeCountSql) {
        this.optimizeCountSql = optimizeCountSql;
        return this;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy