From 571ea137fd122a5c4971f385e6ea03f1ced98a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=80=E6=BA=90=E6=B5=B7=E5=93=A5?= Date: Thu, 1 Jun 2023 18:25:23 +0800 Subject: [PATCH] optimize IService.java --- .../mybatisflex/core/service/IService.java | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) 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 d64a4596..3f82205c 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 @@ -60,6 +60,7 @@ public interface IService { return SqlUtil.toBool(getMapper().insertSelective(entity)); } + /** * 保存或者更新实体类对象数据。 * @@ -149,6 +150,29 @@ public interface IService { return SqlUtil.toBool(getMapper().deleteByMap(query)); } + + /** + * 更加主键更新 entity,默认忽略 null 值 + * + * @param entity 实体类对象 + * @return {@code true} 更新成功,{@code false} 更新失败。 + */ + default boolean updateById(T entity) { + return updateById(entity, true); + } + + + /** + * 更加主键更新 entity + * + * @param entity entity + * @param ignoreNulls 是否忽略 null 值 + * @return {@code true} 更新成功,{@code false} 更新失败。 + */ + default boolean updateById(T entity, boolean ignoreNulls) { + return SqlUtil.toBool(getMapper().update(entity, ignoreNulls)); + } + /** * 根据查询条件更新数据。 * @@ -160,6 +184,18 @@ public interface IService { return SqlUtil.toBool(getMapper().updateByQuery(entity, query)); } + + /** + * 根据 {@link Map} 构建查询条件更新数据。 + * + * @param entity 实体类对象 + * @param query 查询条件 + * @return {@code true} 更新成功,{@code false} 更新失败。 + */ + default boolean update(T entity, Map query) { + return SqlUtil.toBool(getMapper().updateByMap(entity, query)); + } + /** * 根据查询条件更新数据。 * @@ -199,26 +235,6 @@ public interface IService { }); } - /** - * 根据数据主键更新数据。 - * - * @param entity 实体类对象 - * @return {@code true} 更新成功,{@code false} 更新失败。 - */ - default boolean updateById(T entity) { - return SqlUtil.toBool(getMapper().update(entity)); - } - - /** - * 根据 {@link Map} 构建查询条件更新数据。 - * - * @param entity 实体类对象 - * @param query 查询条件 - * @return {@code true} 更新成功,{@code false} 更新失败。 - */ - default boolean updateByMap(T entity, Map query) { - return SqlUtil.toBool(getMapper().updateByMap(entity, query)); - } // ===== 查询(查)操作 =====