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