mirror of
https://gitee.com/best_handsome/mybatis-plus-join
synced 2025-07-11 00:02:22 +08:00
添加注释以及test
This commit is contained in:
parent
740c19511c
commit
c1463c9c9c
@ -94,7 +94,7 @@ public class MybatisPlusJoinAutoConfiguration {
|
||||
}
|
||||
|
||||
/**
|
||||
* springboot content 工具类
|
||||
* springboot context 工具类
|
||||
*/
|
||||
@Bean
|
||||
@Order(Ordered.HIGHEST_PRECEDENCE)
|
||||
|
@ -3,7 +3,8 @@
|
||||
{
|
||||
"sourceType": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties",
|
||||
"name": "mybatis-plus-join",
|
||||
"type": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties"
|
||||
"type": "com.github.yulichang.autoconfigure.MybatisPlusJoinProperties",
|
||||
"description": "mybatis-plus-join configure."
|
||||
}
|
||||
],
|
||||
"properties": [
|
||||
@ -43,5 +44,20 @@
|
||||
"type": "java.lang.String",
|
||||
"description": "逻辑删除的位置支持where和on两个."
|
||||
}
|
||||
],
|
||||
"hints": [
|
||||
{
|
||||
"name": "mybatis-plus-join.logic-del-type",
|
||||
"values": [
|
||||
{
|
||||
"value": "where",
|
||||
"description": "logic delete condition to where."
|
||||
},
|
||||
{
|
||||
"value": "on",
|
||||
"description": "logic delete condition to on."
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -10,7 +10,7 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 链式调用
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -27,7 +27,7 @@ public interface Chain<T> {
|
||||
/**
|
||||
* 链式调用 等效于 selectOne
|
||||
* <p>
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -40,7 +40,7 @@ public interface Chain<T> {
|
||||
/**
|
||||
* 链式调用 等效于 selectJoinOne
|
||||
* <p>
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -53,7 +53,7 @@ public interface Chain<T> {
|
||||
/**
|
||||
* 链式调用 查询列表第一个 匹配多个不会抛异常
|
||||
* <p>
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -67,7 +67,7 @@ public interface Chain<T> {
|
||||
/**
|
||||
* 链式调用 查询列表第一个 匹配多个不会抛异常
|
||||
* <p>
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -80,7 +80,7 @@ public interface Chain<T> {
|
||||
|
||||
/**
|
||||
* 链式调用
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -92,7 +92,7 @@ public interface Chain<T> {
|
||||
|
||||
/**
|
||||
* 链式调用
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -104,7 +104,7 @@ public interface Chain<T> {
|
||||
|
||||
/**
|
||||
* 链式调用
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
@ -116,7 +116,7 @@ public interface Chain<T> {
|
||||
|
||||
/**
|
||||
* 链式调用
|
||||
* 构造方法不须传 class 或 entity 否则会报错
|
||||
* 构造方法必须传 class 或 entity 否则会报错
|
||||
* new MPJLambdaWrapper(User.class)
|
||||
* new MPJQueryWrapper(User.class)
|
||||
* MPJWrappers.\<User\>lambdaJoin(User.class)
|
||||
|
@ -2,6 +2,12 @@ package com.github.yulichang.wrapper.resultmap;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 映射标签
|
||||
*
|
||||
* @author yulichang
|
||||
* @since 2023/3/17 11:35
|
||||
*/
|
||||
public interface Label<T> {
|
||||
|
||||
String getProperty();
|
||||
|
@ -1,9 +1,12 @@
|
||||
package com.github.yulichang.wrapper.resultmap;
|
||||
|
||||
import com.baomidou.mybatisplus.core.metadata.TableInfo;
|
||||
import com.baomidou.mybatisplus.core.toolkit.Assert;
|
||||
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
|
||||
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
|
||||
import com.github.yulichang.toolkit.LambdaUtils;
|
||||
import com.github.yulichang.toolkit.MPJReflectionKit;
|
||||
import com.github.yulichang.toolkit.TableHelper;
|
||||
import com.github.yulichang.toolkit.support.ColumnCache;
|
||||
import com.github.yulichang.wrapper.segments.SelectCache;
|
||||
import lombok.Getter;
|
||||
@ -222,6 +225,13 @@ public class MybatisLabelFree<T> implements Label<T> {
|
||||
}
|
||||
|
||||
public MybatisLabelFree<T> build() {
|
||||
if (CollectionUtils.isEmpty(mybatisLabel.resultList)) {
|
||||
TableInfo tableInfo = TableHelper.get(mybatisLabel.ofType);
|
||||
Assert.notNull(tableInfo,
|
||||
"无法自动映射, 找不到 <%s> 对应的表, 请使用 .all(xxx.class), id()或者result() 手动映射",
|
||||
mybatisLabel.ofType.getSimpleName());
|
||||
all(mybatisLabel.ofType);
|
||||
}
|
||||
return mybatisLabel;
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ import org.springframework.boot.test.context.SpringBootTest;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 连表测试类
|
||||
@ -80,7 +81,7 @@ class CollectionTest {
|
||||
.leftJoin(TableE.class, TableE::getDid, TableD::getId)
|
||||
.last("LIMIT 1");
|
||||
List<TableADTO> dtos1 = tableAMapper.selectJoinList(TableADTO.class, wrapper1);
|
||||
System.out.println(1);
|
||||
assert dtos1.get(0).getB().getC().getD().getE().getId() != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -97,4 +98,42 @@ class CollectionTest {
|
||||
List<TableDTO> dtos = tableMapper.selectJoinList(TableDTO.class, wrapper);
|
||||
System.out.println(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFree(){
|
||||
MPJLambdaWrapper<TableA> wrapper1 = new MPJLambdaWrapper<TableA>()
|
||||
.selectAll(TableA.class)
|
||||
.selectAssociation(TableADTO::getB, b -> b
|
||||
.all(TableB.class)
|
||||
.association(TableC.class, TableBDTO::getC, c -> c
|
||||
.association(TableD.class, TableCDTO::getD, d -> d
|
||||
.association(TableE.class, TableDDTO::getE, e -> e
|
||||
.id(TableE::getId)))))
|
||||
.leftJoin(TableB.class, TableB::getAid, TableA::getId)
|
||||
.leftJoin(TableC.class, TableC::getBid, TableB::getId)
|
||||
.leftJoin(TableD.class, TableD::getCid, TableC::getId)
|
||||
.leftJoin(TableE.class, TableE::getDid, TableD::getId)
|
||||
.last("LIMIT 1");
|
||||
List<TableADTO> dtos1 = tableAMapper.selectJoinList(TableADTO.class, wrapper1);
|
||||
assert dtos1.get(0).getB().getC().getD().getE().getId() != null;
|
||||
|
||||
|
||||
MPJLambdaWrapper<TableA> wrapper2 = new MPJLambdaWrapper<TableA>()
|
||||
.selectAll(TableA.class)
|
||||
.selectAssociation(TableADTO::getB, b -> b
|
||||
.id(TableB::getId)
|
||||
.result(TableD::getName,TableBDTO::getName)
|
||||
.association(TableC.class, TableBDTO::getC, c -> c
|
||||
.association(TableD.class, TableCDTO::getD, d -> d
|
||||
.association(TableE.class, TableDDTO::getE, e -> e
|
||||
.id(TableE::getId)))))
|
||||
.leftJoin(TableB.class, TableB::getAid, TableA::getId)
|
||||
.leftJoin(TableC.class, TableC::getBid, TableB::getId)
|
||||
.leftJoin(TableD.class, TableD::getCid, TableC::getId)
|
||||
.leftJoin(TableE.class, TableE::getDid, TableD::getId)
|
||||
.last("LIMIT 1");
|
||||
List<TableADTO> dtos2 = tableAMapper.selectJoinList(TableADTO.class, wrapper2);
|
||||
assert dtos2.get(0).getB().getC().getD().getE().getId() != null;
|
||||
assert Objects.equals(dtos2.get(0).getB().getName(), "tableD1");
|
||||
}
|
||||
}
|
||||
|
@ -20,8 +20,9 @@ mybatis-plus:
|
||||
configuration:
|
||||
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
|
||||
|
||||
# 打印 mybatis plus join banner
|
||||
mybatis-plus-join:
|
||||
# 打印 mybatis plus join banner
|
||||
banner: true
|
||||
sub-table-logic: true
|
||||
ms-cache: true
|
||||
ms-cache: true
|
||||
logic-del-type: where
|
Loading…
x
Reference in New Issue
Block a user