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

com.github.aly8246.collectionutil.util.IPage 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!

There is a newer version: 1.1.1.RELEASE
Show newest version
package com.github.aly8246.collectionutil.util;

import com.github.aly8246.collectionutil.core.PageInterface;
import com.github.aly8246.collectionutil.main.CollectionInterceptor;

import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * Mybatis plus 的IPage类,用于返回mp风格的分页
 *
 * @author 南有乔木
 * @version v.1.0.7
 * @see Page
 */
public interface IPage extends Serializable {
    default String[] descs() {
        return null;
    }

    default String[] ascs() {
        return null;
    }

    default Map condition() {
        return null;
    }

    default boolean optimizeCountSql() {
        return true;
    }

    default boolean isSearchCount() {
        return true;
    }

    default long offset() {
        return this.getCurrent() > 0L ? (this.getCurrent() - 1L) * this.getSize() : 0L;
    }

    default long getPages() {
        if (this.getSize() == 0L) {
            return 0L;
        } else {
            long pages = this.getTotal() / this.getSize();
            if (this.getTotal() % this.getSize() != 0L) {
                ++pages;
            }

            return pages;
        }
    }

    default IPage setPages(long pages) {
        return this;
    }

    List getRecords();

    IPage setRecords(List records);

    long getTotal();

    IPage setTotal(long total);

    long getSize();

    IPage setSize(long size);

    long getCurrent();

    IPage setCurrent(long current);

    default  IPage convert(Function mapper) {
        List collect = this.getRecords().stream().map(mapper).collect(Collectors.toList());
        return this.setRecords(collect);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy