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

com.github.yulichang.wrapper.interfaces.Chain Maven / Gradle / Ivy

There is a newer version: 1.5.2
Show newest version
package com.github.yulichang.wrapper.interfaces;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.yulichang.interfaces.MPJBaseJoin;
import com.github.yulichang.toolkit.SqlHelper;

import java.util.List;
import java.util.Map;
import java.util.Optional;

/**
 * 链式调用
 * 

* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
* * @author yulichang * @since 1.4.4 */ @SuppressWarnings("unused") public interface Chain extends MPJBaseJoin { Class getEntityClass(); boolean isResultMapCollection(); /** * 链式调用 等效于MP mapper的 selectCount() *

* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default Long count() { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinCount(this)); } /** * 链式调用 等效于 selectOne *

* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default T one() { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinOne(getEntityClass(), this)); } /** * 链式调用 等效于 selectJoinOne *

* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default R one(Class resultType) { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinOne(resultType, this)); } /** * 链式调用 查询列表第一个 匹配多个不会抛异常 *

* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default T first() { List list = this.isResultMapCollection() ? list() : page(new Page(1, 1).setSearchCount(false)).getRecords(); return Optional.of(list).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); } /** * 链式调用 查询列表第一个 匹配多个不会抛异常 *

* 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default R first(Class resultType) { List list = this.isResultMapCollection() ? list(resultType) : page(new Page(1, 1).setSearchCount(false), resultType).getRecords(); return Optional.of(list).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default List list() { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinList(getEntityClass(), this)); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default List list(Class resultType) { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinList(resultType, this)); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default

> P page(P page) { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinPage(page, getEntityClass(), this)); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default > P page(P page, Class resultType) { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinPage(page, resultType, this)); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default Map mapOne() { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinMap(this)); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default Map mapFirst() { List> mapList = mapPage(new Page>(1, 1).setSearchCount(false)).getRecords(); return Optional.of(mapList).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default List> mapList() { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinMaps(this)); } /** * 链式调用 * 构造方法必须传 class 或 entity 否则会报错
* new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ default

>> P mapPage(P page) { return SqlHelper.exec(getEntityClass(), mapper -> mapper.selectJoinMapsPage(page, this)); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy