From 211ad6ac166574acd874d5f3a2a33158c5c04f4c Mon Sep 17 00:00:00 2001 From: Wudadada <819387826@qq.com> Date: Mon, 19 Aug 2024 12:01:59 +0800 Subject: [PATCH 1/3] =?UTF-8?q?feat(mybatis-flex-core):=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0updateBatch=E6=96=B9=E6=B3=95=E6=98=AF=E5=90=A6?= =?UTF-8?q?=E5=BF=BD=E7=95=A5null=E5=AD=97=E6=AE=B5=E7=9A=84=E5=8F=AF?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/base/service.md | 12 ++++++------ .../com/mybatisflex/core/service/IService.java | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/docs/zh/base/service.md b/docs/zh/base/service.md index 91bb75f0..2abe59c7 100644 --- a/docs/zh/base/service.md +++ b/docs/zh/base/service.md @@ -20,15 +20,15 @@ public interface IAccountService extends IService { ```java @Component -public class AccountServiceImpl extends ServiceImpl +public class AccountServiceImpl extends ServiceImpl implements IAccountService { - + @Override public List customMethod() { // 返回 id >= 100 的数据 return list(ACCOUNT.ID.ge(100)); } - + } ``` @@ -63,8 +63,8 @@ public class AccountServiceImpl extends ServiceImpl - **update(entity, map)**:根据 `Map<字段名,值>` 组成的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 - **update(entity, query)**:根据 `QueryWrapper` 构建的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 - **update(entity, condition)**:根据 `QueryCondition` 构建的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 -- **updateBatch(entities)**:批量保存多条数据,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。 -- **updateBatch(entities, size)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。。 +- **updateBatch(entities, ignoreNulls)**:批量保存多条数据,要求主键值不能为空,否则会抛出异常;可以选择数据为 null 的字段是否更新到数据库。 +- **updateBatch(entities, size, ignoreNulls)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;可以选择数据为 null 的字段是否更新到数据库。 ## 查询数据 @@ -117,4 +117,4 @@ public class AccountServiceImpl extends ServiceImpl ## 其他方法 - **getMapper()**:获取对应的 `BaseMapper` 接口。 -- **query()**:获取默认的 `QueryWrapper` 类。 \ No newline at end of file +- **query()**:获取默认的 `QueryWrapper` 类。 diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java index 2e952d0a..613745e1 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java @@ -262,11 +262,14 @@ public interface IService { *

根据数据主键批量更新数据 * * @param entities 实体类对象集合 + * @param ignoreNulls 是否忽略空字段 + * {@code true} 表示忽略实体类中为 {@code null} 的字段,不更新这些字段。 + * {@code false} 表示不忽略空字段,允许将对应字段更新为 {@code null}。 * @return boolean {@code true} 更新成功,{@code false} 更新失败。 - * @apiNote 若实体类属性数据为 {@code null},该属性不会新到数据库。 + * @apiNote 若 {@code ignoreNulls} 为 {@code true},实体类中为 {@code null} 的属性不会更新到数据库。 */ - default boolean updateBatch(Collection entities) { - return updateBatch(entities, DEFAULT_BATCH_SIZE); + default boolean updateBatch(Collection entities, Boolean ignoreNulls) { + return updateBatch(entities, DEFAULT_BATCH_SIZE, ignoreNulls); } /** @@ -274,12 +277,15 @@ public interface IService { * * @param entities 实体类对象集合 * @param batchSize 每批次更新数量 + * @param ignoreNulls 是否忽略空字段 + * {@code true} 表示忽略实体类中为 {@code null} 的字段,不更新这些字段。 + * {@code false} 表示不忽略空字段,允许将对应字段更新为 {@code null}。 * @return {@code true} 更新成功,{@code false} 更新失败。 - * @apiNote 若实体类属性数据为 {@code null},该属性不会新到数据库。 + * @apiNote 若 {@code ignoreNulls} 为 {@code true},实体类中为 {@code null} 的属性不会更新到数据库。 */ - default boolean updateBatch(Collection entities, int batchSize) { + default boolean updateBatch(Collection entities, int batchSize, boolean ignoreNulls) { Class> usefulClass = (Class>) ClassUtil.getUsefulClass(getMapper().getClass()); - return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::update)); + return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls))); } // ===== 查询(查)操作 ===== From 7bbc31ccf00debf82391f447e53fcc29c3c01467 Mon Sep 17 00:00:00 2001 From: Wudadada <819387826@qq.com> Date: Mon, 19 Aug 2024 17:18:07 +0800 Subject: [PATCH 2/3] =?UTF-8?q?Revert=20"feat(mybatis-flex-core):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0updateBatch=E6=96=B9=E6=B3=95=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=BF=BD=E7=95=A5null=E5=AD=97=E6=AE=B5=E7=9A=84?= =?UTF-8?q?=E5=8F=AF=E9=85=8D=E7=BD=AE=E6=80=A7"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 211ad6ac166574acd874d5f3a2a33158c5c04f4c. --- docs/zh/base/service.md | 12 ++++++------ .../com/mybatisflex/core/service/IService.java | 18 ++++++------------ 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/docs/zh/base/service.md b/docs/zh/base/service.md index 2abe59c7..91bb75f0 100644 --- a/docs/zh/base/service.md +++ b/docs/zh/base/service.md @@ -20,15 +20,15 @@ public interface IAccountService extends IService { ```java @Component -public class AccountServiceImpl extends ServiceImpl +public class AccountServiceImpl extends ServiceImpl implements IAccountService { - + @Override public List customMethod() { // 返回 id >= 100 的数据 return list(ACCOUNT.ID.ge(100)); } - + } ``` @@ -63,8 +63,8 @@ public class AccountServiceImpl extends ServiceImpl - **update(entity, map)**:根据 `Map<字段名,值>` 组成的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 - **update(entity, query)**:根据 `QueryWrapper` 构建的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 - **update(entity, condition)**:根据 `QueryCondition` 构建的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 -- **updateBatch(entities, ignoreNulls)**:批量保存多条数据,要求主键值不能为空,否则会抛出异常;可以选择数据为 null 的字段是否更新到数据库。 -- **updateBatch(entities, size, ignoreNulls)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;可以选择数据为 null 的字段是否更新到数据库。 +- **updateBatch(entities)**:批量保存多条数据,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。 +- **updateBatch(entities, size)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。。 ## 查询数据 @@ -117,4 +117,4 @@ public class AccountServiceImpl extends ServiceImpl ## 其他方法 - **getMapper()**:获取对应的 `BaseMapper` 接口。 -- **query()**:获取默认的 `QueryWrapper` 类。 +- **query()**:获取默认的 `QueryWrapper` 类。 \ No newline at end of file diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java index 613745e1..2e952d0a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java @@ -262,14 +262,11 @@ public interface IService { *

根据数据主键批量更新数据 * * @param entities 实体类对象集合 - * @param ignoreNulls 是否忽略空字段 - * {@code true} 表示忽略实体类中为 {@code null} 的字段,不更新这些字段。 - * {@code false} 表示不忽略空字段,允许将对应字段更新为 {@code null}。 * @return boolean {@code true} 更新成功,{@code false} 更新失败。 - * @apiNote 若 {@code ignoreNulls} 为 {@code true},实体类中为 {@code null} 的属性不会更新到数据库。 + * @apiNote 若实体类属性数据为 {@code null},该属性不会新到数据库。 */ - default boolean updateBatch(Collection entities, Boolean ignoreNulls) { - return updateBatch(entities, DEFAULT_BATCH_SIZE, ignoreNulls); + default boolean updateBatch(Collection entities) { + return updateBatch(entities, DEFAULT_BATCH_SIZE); } /** @@ -277,15 +274,12 @@ public interface IService { * * @param entities 实体类对象集合 * @param batchSize 每批次更新数量 - * @param ignoreNulls 是否忽略空字段 - * {@code true} 表示忽略实体类中为 {@code null} 的字段,不更新这些字段。 - * {@code false} 表示不忽略空字段,允许将对应字段更新为 {@code null}。 * @return {@code true} 更新成功,{@code false} 更新失败。 - * @apiNote 若 {@code ignoreNulls} 为 {@code true},实体类中为 {@code null} 的属性不会更新到数据库。 + * @apiNote 若实体类属性数据为 {@code null},该属性不会新到数据库。 */ - default boolean updateBatch(Collection entities, int batchSize, boolean ignoreNulls) { + default boolean updateBatch(Collection entities, int batchSize) { Class> usefulClass = (Class>) ClassUtil.getUsefulClass(getMapper().getClass()); - return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls))); + return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::update)); } // ===== 查询(查)操作 ===== From d8159227e6100fd35825ed23df4c8b314c0875e4 Mon Sep 17 00:00:00 2001 From: Wudadada <819387826@qq.com> Date: Mon, 19 Aug 2024 17:22:31 +0800 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E4=BF=9D=E7=95=99=E5=8E=9F=E6=9C=89?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=8C=E5=A2=9E=E5=8A=A0=E5=8F=AF=E9=85=8D?= =?UTF-8?q?=E7=BD=AE=E6=98=AF=E5=90=A6=E5=BF=BD=E7=95=A5null=E5=AD=97?= =?UTF-8?q?=E6=AE=B5=E7=9A=84updateBatch=E6=96=B9=E6=B3=95=3D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/base/service.md | 12 ++++---- .../mybatisflex/core/service/IService.java | 30 +++++++++++++++++++ 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/docs/zh/base/service.md b/docs/zh/base/service.md index 91bb75f0..65aa1e02 100644 --- a/docs/zh/base/service.md +++ b/docs/zh/base/service.md @@ -20,15 +20,15 @@ public interface IAccountService extends IService { ```java @Component -public class AccountServiceImpl extends ServiceImpl +public class AccountServiceImpl extends ServiceImpl implements IAccountService { - + @Override public List customMethod() { // 返回 id >= 100 的数据 return list(ACCOUNT.ID.ge(100)); } - + } ``` @@ -64,7 +64,9 @@ public class AccountServiceImpl extends ServiceImpl - **update(entity, query)**:根据 `QueryWrapper` 构建的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 - **update(entity, condition)**:根据 `QueryCondition` 构建的条件更新数据,实体类可以没有主键(如果有也会被忽略),实体类的 null 属性,会自动被忽略。 - **updateBatch(entities)**:批量保存多条数据,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。 -- **updateBatch(entities, size)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。。 +- **updateBatch(entities, ignoreNulls)**:批量保存多条数据,要求主键值不能为空,否则会抛出异常;可以选择数据为 null 的字段是否更新到数据库。 +- **updateBatch(entities, size)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;同时,数据为 null 的字段不会更新到数据库。 +- **updateBatch(entities, size, ignoreNulls)**:批量保存多条数据,按指定数量切分,要求主键值不能为空,否则会抛出异常;可以选择数据为 null 的字段是否更新到数据库。 ## 查询数据 @@ -117,4 +119,4 @@ public class AccountServiceImpl extends ServiceImpl ## 其他方法 - **getMapper()**:获取对应的 `BaseMapper` 接口。 -- **query()**:获取默认的 `QueryWrapper` 类。 \ No newline at end of file +- **query()**:获取默认的 `QueryWrapper` 类。 diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java index 2e952d0a..4f0a96c5 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/service/IService.java @@ -269,6 +269,20 @@ public interface IService { return updateBatch(entities, DEFAULT_BATCH_SIZE); } + /** + *

根据数据主键批量更新数据 + * + * @param entities 实体类对象集合 + * @param ignoreNulls 是否忽略空字段 + * {@code true} 表示忽略实体类中为 {@code null} 的字段,不更新这些字段。 + * {@code false} 表示不忽略空字段,允许将对应字段更新为 {@code null}。 + * @return boolean {@code true} 更新成功,{@code false} 更新失败。 + * @apiNote 若 {@code ignoreNulls} 为 {@code true},实体类中为 {@code null} 的属性不会更新到数据库。 + */ + default boolean updateBatch(Collection entities, Boolean ignoreNulls) { + return updateBatch(entities, DEFAULT_BATCH_SIZE, ignoreNulls); + } + /** *

根据数据主键批量更新数据 * @@ -282,6 +296,22 @@ public interface IService { return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::update)); } + /** + *

根据数据主键批量更新数据 + * + * @param entities 实体类对象集合 + * @param batchSize 每批次更新数量 + * @param ignoreNulls 是否忽略空字段 + * {@code true} 表示忽略实体类中为 {@code null} 的字段,不更新这些字段。 + * {@code false} 表示不忽略空字段,允许将对应字段更新为 {@code null}。 + * @return {@code true} 更新成功,{@code false} 更新失败。 + * @apiNote 若 {@code ignoreNulls} 为 {@code true},实体类中为 {@code null} 的属性不会更新到数据库。 + */ + default boolean updateBatch(Collection entities, int batchSize, boolean ignoreNulls) { + Class> usefulClass = (Class>) ClassUtil.getUsefulClass(getMapper().getClass()); + return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls))); + } + // ===== 查询(查)操作 ===== /**