diff --git a/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser-v46/pom.xml b/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser-v46/pom.xml index a2797c8..049eedd 100644 --- a/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser-v46/pom.xml +++ b/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser-v46/pom.xml @@ -35,15 +35,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.baomidou diff --git a/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser/pom.xml b/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser/pom.xml index 94ab7fc..8e2f934 100644 --- a/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser/pom.xml +++ b/mybatis-plus-join-adapter/jsqlparser/mybatis-plus-join-adapter-jsqlparser/pom.xml @@ -35,15 +35,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.baomidou diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml index a1e2238..1ede94f 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v33x/pom.xml @@ -33,15 +33,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.github.yulichang diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v3431/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v3431/pom.xml index 1e15545..9e01502 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v3431/pom.xml +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v3431/pom.xml @@ -33,15 +33,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.github.yulichang diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml index 6613bc5..18e17bb 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v352/pom.xml @@ -33,15 +33,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.baomidou diff --git a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v355/pom.xml b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v355/pom.xml index 955a389..fcf5a80 100644 --- a/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v355/pom.xml +++ b/mybatis-plus-join-adapter/mybatis-plus-join-adapter-v355/pom.xml @@ -33,15 +33,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.github.yulichang diff --git a/mybatis-plus-join-annotation/pom.xml b/mybatis-plus-join-annotation/pom.xml index c913b49..2eed187 100644 --- a/mybatis-plus-join-annotation/pom.xml +++ b/mybatis-plus-join-annotation/pom.xml @@ -33,13 +33,4 @@ scm:git:https://github.com/yulichang/mybatis-plus-join.git https://github.com/yulichang/mybatis-plus-join - - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractLambdaWrapper.java index 9dc9940..3e63f0d 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/KtAbstractLambdaWrapper.java @@ -55,6 +55,8 @@ public abstract class KtAbstractLambdaWrapper extends KtAbstractLambdaWrapper label) { + public void addLabel(Label label, boolean isCollection) { + if (isCollection) { + this.resultMapCollection = true; + } this.resultMap = true; this.resultMapMybatisLabel.add(label); } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/interfaces/QueryLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/interfaces/QueryLabel.java index d5f4571..f2d00b8 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/interfaces/QueryLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/kt/interfaces/QueryLabel.java @@ -23,7 +23,7 @@ import java.util.Map; @SuppressWarnings({"unused", "DuplicatedCode"}) public interface QueryLabel { - void addLabel(Label label); + void addLabel(Label label, boolean isCollection); Children getChildren(); @@ -62,7 +62,7 @@ public interface QueryLabel { } else { builder = new MybatisLabel.Builder<>(prefix, dtoFieldName, child, field.getType(), genericType, true); } - addLabel(builder.build()); + addLabel(builder.build(), true); return getChildren(); } @@ -104,7 +104,7 @@ public interface QueryLabel { Class genericType = MPJReflectionKit.getGenericType(field.getField()); MybatisLabelFree.Builder builder = new MybatisLabelFree.Builder<>(dtoFieldName, field.getType(), genericType); MybatisLabelFree.Builder czBuilder = collection.apply(builder); - addLabel(czBuilder.build()); + addLabel(czBuilder.build(), true); return getChildren(); } @@ -118,7 +118,7 @@ public interface QueryLabel { Class genericType = MPJReflectionKit.getGenericType(field.getField()); MybatisLabel.Builder builder = new MybatisLabel.Builder<>(prefix, dtoFieldName, child, field.getType(), genericType, false); MybatisLabel.Builder czBuilder = collection.apply(builder); - addLabel(czBuilder.build()); + addLabel(czBuilder.build(), true); return getChildren(); } @@ -139,7 +139,7 @@ public interface QueryLabel { MybatisLabel.Builder builder; builder = new MybatisLabel.Builder<>(StringUtils.isBlank(prefix) ? null : prefix, dtoFieldName, child, field.getType(), (Class) field.getType(), true); - addLabel(builder.build()); + addLabel(builder.build(), false); return getChildren(); } @@ -160,7 +160,7 @@ public interface QueryLabel { Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabelFree.Builder builder = new MybatisLabelFree.Builder<>(dtoFieldName, field.getType(), (Class) field.getType()); MybatisLabelFree.Builder cfBuilder = collection.apply(builder); - addLabel(cfBuilder.build()); + addLabel(cfBuilder.build(), false); return getChildren(); } @@ -172,7 +172,7 @@ public interface QueryLabel { MybatisLabel.Builder builder = new MybatisLabel.Builder<>(StringUtils.isBlank(prefix) ? null : prefix, dtoFieldName, child, field.getType(), (Class) field.getType(), false); MybatisLabel.Builder cfBuilder = collection.apply(builder); - addLabel(cfBuilder.build()); + addLabel(cfBuilder.build(), false); return getChildren(); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java index 7be9335..e3a9625 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/query/MPJQueryWrapper.java @@ -364,6 +364,11 @@ public class MPJQueryWrapper extends AbstractWrapper setEntityClass(Class entityClass) { try { diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java index d4e3380..9485bbb 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/JoinAbstractLambdaWrapper.java @@ -48,10 +48,15 @@ public abstract class JoinAbstractLambdaWrapper extends JoinAbstractLambdaWrapper label) { + public void addLabel(Label label, boolean isCollection) { + if (isCollection) { + this.resultMapCollection = true; + } this.resultMap = true; this.resultMapMybatisLabel.add(label); } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/AptAbstractWrapper.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/AptAbstractWrapper.java index 02f3610..5223765 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/AptAbstractWrapper.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/AptAbstractWrapper.java @@ -56,6 +56,8 @@ public abstract class AptAbstractWrapper extends AptAbstractWrapper } @Override - public void addLabel(Label label) { + public void addLabel(Label label, boolean isCollection) { + if (isCollection) { + this.resultMapCollection = true; + } this.resultMap = true; this.resultMapMybatisLabel.add(label); } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/interfaces/QueryLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/interfaces/QueryLabel.java index 3bdd2c4..411cb6c 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/interfaces/QueryLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/apt/interfaces/QueryLabel.java @@ -23,7 +23,7 @@ import java.util.Map; @SuppressWarnings({"unchecked", "unused", "DuplicatedCode"}) public interface QueryLabel { - void addLabel(Label label); + void addLabel(Label label, boolean isCollection); Children getChildren(); @@ -65,7 +65,7 @@ public interface QueryLabel { Class ofType = (Class) genericType; builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), ofType, true); } - addLabel(builder.build()); + addLabel(builder.build(), true); return getChildren(); } @@ -108,7 +108,7 @@ public interface QueryLabel { Class ofType = (Class) genericType; MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), ofType, false); MybatisLabel.Builder czBuilder = collection.apply(builder); - addLabel(czBuilder.build()); + addLabel(czBuilder.build(), true); return getChildren(); } @@ -124,7 +124,7 @@ public interface QueryLabel { Class ofType = (Class) genericType; MybatisLabelFree.Builder builder = new MybatisLabelFree.Builder<>(dtoFieldName, field.getType(), ofType); MybatisLabelFree.Builder czBuilder = collection.apply(builder); - addLabel(czBuilder.build()); + addLabel(czBuilder.build(), true); return getChildren(); } @@ -142,7 +142,7 @@ public interface QueryLabel { Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabel.Builder builder; builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) field.getType(), true); - addLabel(builder.build()); + addLabel(builder.build(), false); return getChildren(); } @@ -154,7 +154,7 @@ public interface QueryLabel { Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabelFree.Builder builder = new MybatisLabelFree.Builder<>(dtoFieldName, field.getType(), (Class) field.getType()); MybatisLabelFree.Builder cfBuilder = collection.apply(builder); - addLabel(cfBuilder.build()); + addLabel(cfBuilder.build(), false); return getChildren(); } @@ -166,7 +166,7 @@ public interface QueryLabel { Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabel.Builder builder = new MybatisLabel.Builder<>(dtoFieldName, child, field.getType(), (Class) field.getType(), false); MybatisLabel.Builder cfBuilder = collection.apply(builder); - addLabel(cfBuilder.build()); + addLabel(cfBuilder.build(), false); return getChildren(); } } diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java index ad2eb8e..ce50591 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/Chain.java @@ -2,6 +2,7 @@ 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; @@ -21,8 +22,12 @@ import java.util.Optional; @SuppressWarnings("unused") public interface Chain extends MPJBaseJoin { + Page FIRST_PAGE = new Page<>(1, 1).setSearchCount(false); + Class getEntityClass(); + boolean isResultMapCollection(); + /** * 链式调用 等效于MP mapper的 selectCount() *

@@ -63,8 +68,10 @@ public interface Chain extends MPJBaseJoin { * new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ + @SuppressWarnings("unchecked") default T first() { - return Optional.of(list()).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); + List list = this.isResultMapCollection() ? list() : page((Page) FIRST_PAGE).getRecords(); + return Optional.of(list).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); } /** @@ -74,8 +81,10 @@ public interface Chain extends MPJBaseJoin { * new MPJLambdaWrapper(User.class)
* JoinWrappers.lambda(User.class)
*/ + @SuppressWarnings("unchecked") default R first(Class resultType) { - return Optional.of(list(resultType)).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); + List list = this.isResultMapCollection() ? list(resultType) : page((Page) FIRST_PAGE, resultType).getRecords(); + return Optional.of(list).filter(CollectionUtils::isNotEmpty).map(m -> m.get(0)).orElse(null); } /** diff --git a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java index 5bb55b9..70135f8 100644 --- a/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java +++ b/mybatis-plus-join-core/src/main/java/com/github/yulichang/wrapper/interfaces/QueryLabel.java @@ -22,7 +22,7 @@ import java.util.Map; @SuppressWarnings({"unchecked", "unused", "DuplicatedCode"}) public interface QueryLabel { - void addLabel(Label label); + void addLabel(Label label, boolean isCollection); Children getChildren(); @@ -67,7 +67,7 @@ public interface QueryLabel { Class ofType = (Class) genericType; builder = new MybatisLabel.Builder<>(prefix, dtoFieldName, child, field.getType(), ofType, true); } - addLabel(builder.build()); + addLabel(builder.build(), true); return getChildren(); } @@ -116,7 +116,7 @@ public interface QueryLabel { Class ofType = (Class) genericType; MybatisLabelFree.Builder builder = new MybatisLabelFree.Builder<>(dtoFieldName, field.getType(), ofType); MybatisLabelFree.Builder czBuilder = collection.apply(builder); - addLabel(czBuilder.build()); + addLabel(czBuilder.build(), true); return getChildren(); } @@ -132,7 +132,7 @@ public interface QueryLabel { Class ofType = (Class) genericType; MybatisLabel.Builder builder = new MybatisLabel.Builder<>(prefix, dtoFieldName, child, field.getType(), ofType, false); MybatisLabel.Builder czBuilder = collection.apply(builder); - addLabel(czBuilder.build()); + addLabel(czBuilder.build(), true); return getChildren(); } @@ -154,7 +154,7 @@ public interface QueryLabel { MybatisLabel.Builder builder; builder = new MybatisLabel.Builder<>(StringUtils.isBlank(prefix) ? null : prefix, dtoFieldName, child, field.getType(), (Class) field.getType(), true); - addLabel(builder.build()); + addLabel(builder.build(), false); return getChildren(); } @@ -176,7 +176,7 @@ public interface QueryLabel { Assert.isFalse(Collection.class.isAssignableFrom(field.getType()), "association 不支持集合类"); MybatisLabelFree.Builder builder = new MybatisLabelFree.Builder<>(dtoFieldName, field.getType(), (Class) field.getType()); MybatisLabelFree.Builder cfBuilder = collection.apply(builder); - addLabel(cfBuilder.build()); + addLabel(cfBuilder.build(), false); return getChildren(); } @@ -189,7 +189,7 @@ public interface QueryLabel { MybatisLabel.Builder builder = new MybatisLabel.Builder<>(StringUtils.isBlank(prefix) ? null : prefix, dtoFieldName, child, field.getType(), (Class) field.getType(), false); MybatisLabel.Builder cfBuilder = collection.apply(builder); - addLabel(cfBuilder.build()); + addLabel(cfBuilder.build(), false); return getChildren(); } } diff --git a/mybatis-plus-join-extension/pom.xml b/mybatis-plus-join-extension/pom.xml index 52fafa0..5bbbb0f 100644 --- a/mybatis-plus-join-extension/pom.xml +++ b/mybatis-plus-join-extension/pom.xml @@ -33,15 +33,6 @@ https://github.com/yulichang/mybatis-plus-join - - 1.8 - 1.8 - 1.8 - 1.8 - github - UTF-8 - - com.github.yulichang diff --git a/mybatis-plus-join-test/test-base/pom.xml b/mybatis-plus-join-test/test-base/pom.xml index a49d735..ea876dc 100644 --- a/mybatis-plus-join-test/test-base/pom.xml +++ b/mybatis-plus-join-test/test-base/pom.xml @@ -12,10 +12,4 @@ test-base test-base - - - 8 - 8 - UTF-8 - diff --git a/mybatis-plus-join-test/test-collection/pom.xml b/mybatis-plus-join-test/test-collection/pom.xml index fdfa797..593eed1 100644 --- a/mybatis-plus-join-test/test-collection/pom.xml +++ b/mybatis-plus-join-test/test-collection/pom.xml @@ -12,12 +12,6 @@ test-collection - - 8 - 8 - UTF-8 - - com.github.yulichang diff --git a/mybatis-plus-join-test/test-join/pom.xml b/mybatis-plus-join-test/test-join/pom.xml index d0c3e6e..ea5b98b 100644 --- a/mybatis-plus-join-test/test-join/pom.xml +++ b/mybatis-plus-join-test/test-join/pom.xml @@ -12,12 +12,6 @@ test-join - - 1.8 - 1.8 - UTF-8 - - com.github.yulichang diff --git a/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ChainFirstTest.java b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ChainFirstTest.java new file mode 100644 index 0000000..0f1df4c --- /dev/null +++ b/mybatis-plus-join-test/test-join/src/test/java/com/github/yulichang/test/join/unit/ChainFirstTest.java @@ -0,0 +1,46 @@ +package com.github.yulichang.test.join.unit; + +import com.github.yulichang.test.join.entity.UserDO; +import com.github.yulichang.test.util.Reset; +import com.github.yulichang.toolkit.JoinWrappers; +import com.github.yulichang.wrapper.MPJLambdaWrapper; +import com.github.yulichang.wrapper.UpdateJoinWrapper; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +public class ChainFirstTest { + + + @BeforeEach + void setUp() { + Reset.reset(); + } + + + @Test + void chainFirst() { + MPJLambdaWrapper wrapper = JoinWrappers.lambda(UserDO.class) + .select(UserDO::getName); + + String first = wrapper.first(String.class); + + System.out.println(first); + } + + @Test + void chainFirst1() { + UpdateJoinWrapper update = JoinWrappers.update(UserDO.class) + .set(UserDO::getName, null); + update.update(); + + MPJLambdaWrapper wrapper = JoinWrappers.lambda(UserDO.class) + .select(UserDO::getName); + + String first = wrapper.first(String.class); + + System.out.println(first); + } + +} diff --git a/mybatis-plus-join-test/test-mapping/pom.xml b/mybatis-plus-join-test/test-mapping/pom.xml index f481a1c..f5b3645 100644 --- a/mybatis-plus-join-test/test-mapping/pom.xml +++ b/mybatis-plus-join-test/test-mapping/pom.xml @@ -12,12 +12,6 @@ test-mapping - - 8 - 8 - UTF-8 - - com.github.yulichang diff --git a/plugin/mybatis-plus-join-processor/pom.xml b/plugin/mybatis-plus-join-processor/pom.xml index ff41d7b..cf0ff3f 100644 --- a/plugin/mybatis-plus-join-processor/pom.xml +++ b/plugin/mybatis-plus-join-processor/pom.xml @@ -14,12 +14,6 @@ ${revision} jar - - 8 - 8 - UTF-8 - - com.github.yulichang diff --git a/plugin/mybatis-plus-join-solon-plugin/pom.xml b/plugin/mybatis-plus-join-solon-plugin/pom.xml index f73b49b..5c053b0 100644 --- a/plugin/mybatis-plus-join-solon-plugin/pom.xml +++ b/plugin/mybatis-plus-join-solon-plugin/pom.xml @@ -14,9 +14,6 @@ 2.8.0 - 8 - 8 - UTF-8