mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
Merge branch 'pr_1'
This commit is contained in:
commit
990280bfb3
4
pom.xml
4
pom.xml
@ -1,10 +1,10 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>com.github.yulichang</groupId>
|
<groupId>com.github.yulichang</groupId>
|
||||||
<artifactId>mybatis-plus-join</artifactId>
|
<artifactId>mybatis-plus-join</artifactId>
|
||||||
<version>1.2.4</version>
|
<version>1.2.7</version>
|
||||||
<name>mybatis-plus-join</name>
|
<name>mybatis-plus-join</name>
|
||||||
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
<description>An enhanced toolkit of Mybatis-Plus to simplify development.</description>
|
||||||
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
<url>https://github.com/yulichang/mybatis-plus-join</url>
|
||||||
|
@ -10,6 +10,7 @@ import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
|||||||
import com.github.yulichang.toolkit.Constant;
|
import com.github.yulichang.toolkit.Constant;
|
||||||
import com.github.yulichang.toolkit.LambdaUtils;
|
import com.github.yulichang.toolkit.LambdaUtils;
|
||||||
import com.github.yulichang.toolkit.MPJWrappers;
|
import com.github.yulichang.toolkit.MPJWrappers;
|
||||||
|
import com.github.yulichang.toolkit.ReflectionKit;
|
||||||
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
import com.github.yulichang.wrapper.enums.BaseFuncEnum;
|
||||||
import com.github.yulichang.wrapper.interfaces.LambdaJoin;
|
import com.github.yulichang.wrapper.interfaces.LambdaJoin;
|
||||||
import com.github.yulichang.wrapper.interfaces.Query;
|
import com.github.yulichang.wrapper.interfaces.Query;
|
||||||
@ -17,6 +18,7 @@ import com.github.yulichang.wrapper.interfaces.on.OnFunction;
|
|||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -38,46 +40,38 @@ import java.util.stream.Collectors;
|
|||||||
public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWrapper<T>>
|
public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWrapper<T>>
|
||||||
implements Query<MPJLambdaWrapper<T>>, LambdaJoin<MPJLambdaWrapper<T>, T> {
|
implements Query<MPJLambdaWrapper<T>>, LambdaJoin<MPJLambdaWrapper<T>, T> {
|
||||||
|
|
||||||
/**
|
|
||||||
* 查询字段 sql
|
|
||||||
*/
|
|
||||||
private SharedString sqlSelect = new SharedString();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询表
|
* 查询表
|
||||||
*/
|
*/
|
||||||
private final SharedString from = new SharedString();
|
private final SharedString from = new SharedString();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 主表别名
|
* 主表别名
|
||||||
*/
|
*/
|
||||||
private final SharedString alias = new SharedString(Constant.TABLE_ALIAS);
|
private final SharedString alias = new SharedString(Constant.TABLE_ALIAS);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询的字段
|
* 查询的字段
|
||||||
*/
|
*/
|
||||||
private final List<SelectColumn> selectColumns = new ArrayList<>();
|
private final List<SelectColumn> selectColumns = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 忽略查询的字段
|
* 忽略查询的字段
|
||||||
*/
|
*/
|
||||||
private final List<SelectColumn> ignoreColumns = new ArrayList<>();
|
private final List<SelectColumn> ignoreColumns = new ArrayList<>();
|
||||||
|
|
||||||
/**
|
|
||||||
* 是否 select distinct
|
|
||||||
*/
|
|
||||||
private boolean selectDistinct = false;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 表序号
|
|
||||||
*/
|
|
||||||
private int tableIndex = 1;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ON sql wrapper集合
|
* ON sql wrapper集合
|
||||||
*/
|
*/
|
||||||
private final List<MPJLambdaWrapper<?>> onWrappers = new ArrayList<>();
|
private final List<MPJLambdaWrapper<?>> onWrappers = new ArrayList<>();
|
||||||
|
/**
|
||||||
|
* 查询字段 sql
|
||||||
|
*/
|
||||||
|
private SharedString sqlSelect = new SharedString();
|
||||||
|
/**
|
||||||
|
* 是否 select distinct
|
||||||
|
*/
|
||||||
|
private boolean selectDistinct = false;
|
||||||
|
/**
|
||||||
|
* 表序号
|
||||||
|
*/
|
||||||
|
private int tableIndex = 1;
|
||||||
/**
|
/**
|
||||||
* 连表关键字 on 条件 func 使用
|
* 连表关键字 on 条件 func 使用
|
||||||
*/
|
*/
|
||||||
@ -149,6 +143,22 @@ public class MPJLambdaWrapper<T> extends MPJAbstractLambdaWrapper<T, MPJLambdaWr
|
|||||||
return typedThis;
|
return typedThis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <E> MPJLambdaWrapper<T> selectAsClass(Class<E> source, Class<?> tag) {
|
||||||
|
TableInfo tableInfo = TableInfoHelper.getTableInfo(source);
|
||||||
|
Assert.notNull(tableInfo, "table can not be find");
|
||||||
|
List<Field> tagFields = ReflectionKit.getFieldList(tag);
|
||||||
|
tableInfo.getFieldList().forEach(i -> {
|
||||||
|
if (tagFields.stream().anyMatch(f -> f.getName().equals(i.getProperty()))) {
|
||||||
|
selectColumns.add(SelectColumn.of(source, i.getColumn()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if (tableInfo.havePK() && tagFields.stream().anyMatch(i -> i.getName().equals(tableInfo.getKeyProperty()))) {
|
||||||
|
selectColumns.add(SelectColumn.of(source, tableInfo.getKeyProperty()));
|
||||||
|
}
|
||||||
|
return typedThis;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <S> MPJLambdaWrapper<T> selectAs(SFunction<S, ?> column, String alias) {
|
public <S> MPJLambdaWrapper<T> selectAs(SFunction<S, ?> column, String alias) {
|
||||||
selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), getCache(column).getColumn(), alias));
|
selectColumns.add(SelectColumn.of(LambdaUtils.getEntityClass(column), getCache(column).getColumn(), alias));
|
||||||
|
@ -39,6 +39,18 @@ public interface Query<Children> extends Serializable {
|
|||||||
*/
|
*/
|
||||||
<E> Children select(Class<E> entityClass, Predicate<TableFieldInfo> predicate);
|
<E> Children select(Class<E> entityClass, Predicate<TableFieldInfo> predicate);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 说明:
|
||||||
|
* 比如我们需要查询用户表有10个字段,然而我们只需要3个就够了,用mybatis-plus提供的select<p />
|
||||||
|
* 需要一个属性一个属性填入很不优雅,现在我们可以用selectAsClass(UserDO.class, UserVo.class)<p />
|
||||||
|
* 即可按所需的UserVo返回,前提是UserVo.class中的属性必须是UserDO.class中存在的
|
||||||
|
*
|
||||||
|
* @param source 数据源实体类
|
||||||
|
* @param tag 目标类
|
||||||
|
* @return children
|
||||||
|
*/
|
||||||
|
<E> Children selectAsClass(Class<E> source, Class<?> tag);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ignore
|
* ignore
|
||||||
*/
|
*/
|
||||||
@ -53,6 +65,11 @@ public interface Query<Children> extends Serializable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 聚合函数查询
|
* 聚合函数查询
|
||||||
|
* <p>
|
||||||
|
* wrapper.selectFunc(() -> "COUNT(%s)", "t.id", "total");
|
||||||
|
* <p>
|
||||||
|
* lambda
|
||||||
|
* wrapper.selectFunc(() -> "COUNT(%s)", UserDO::getId, UserDTO::getTotal);
|
||||||
*
|
*
|
||||||
* @param funcEnum 函数枚举 {@link com.github.yulichang.wrapper.enums.DefaultFuncEnum}
|
* @param funcEnum 函数枚举 {@link com.github.yulichang.wrapper.enums.DefaultFuncEnum}
|
||||||
* @param column 函数作用的字段
|
* @param column 函数作用的字段
|
||||||
|
Loading…
x
Reference in New Issue
Block a user