From a37bdaabf1afaba86ae244d4b7937e3563669f97 Mon Sep 17 00:00:00 2001 From: hewei Date: Sat, 10 May 2025 11:15:30 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AF=B9=E4=BA=8E=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E5=B8=B8=E7=94=A8=E7=B1=BB=EF=BC=8C=E5=90=AF=E7=94=A8=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E6=8A=98=E5=8F=A0=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../codegen/config/GlobalConfig.java | 30 +++++++----- .../java/com/mybatisflex/core/BaseMapper.java | 14 +++--- .../mybatisflex/core/query/QueryMethods.java | 48 ++++++++++++------- .../mybatisflex/core/service/IService.java | 22 +++++---- 4 files changed, 71 insertions(+), 43 deletions(-) diff --git a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java index a22d0a1b..7fe44b32 100644 --- a/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java +++ b/mybatis-flex-codegen/src/main/java/com/mybatisflex/codegen/config/GlobalConfig.java @@ -42,7 +42,7 @@ public class GlobalConfig implements Serializable { private final FileType fileType; - // === 必须配置 === + //region === 必须配置 === public GlobalConfig() { this(FileType.JAVA); @@ -52,8 +52,9 @@ public class GlobalConfig implements Serializable { private final PackageConfig packageConfig; private final StrategyConfig strategyConfig; private final TemplateConfig templateConfig; + //endregion === 必须配置 === - // === 可选配置 === + //region === 可选配置 === private EntityConfig entityConfig; private MapperConfig mapperConfig; @@ -62,11 +63,13 @@ public class GlobalConfig implements Serializable { private ControllerConfig controllerConfig; private TableDefConfig tableDefConfig; private MapperXmlConfig mapperXmlConfig; + //endregion === 可选配置 === - // === 其他自定义配置 === + //region === 其他自定义配置 === private Map customConfig = new HashMap<>(); + //endregion === 其他自定义配置 === - // === 是否启用生成 === + //region === 是否启用生成 === private boolean entityGenerateEnable; private boolean mapperGenerateEnable; @@ -122,8 +125,9 @@ public class GlobalConfig implements Serializable { } } + //endregion === 是否启用生成 === - // === 分类配置 === + //region === 分类配置 === public JavadocConfig getJavadocConfig() { return javadocConfig; @@ -189,8 +193,9 @@ public class GlobalConfig implements Serializable { } return mapperXmlConfig; } + //endregion === 分类配置 === - // === 启用配置 === + //region === 启用配置 === public EntityConfig enableEntity() { entityGenerateEnable = true; @@ -230,8 +235,9 @@ public class GlobalConfig implements Serializable { public void enablePackageInfo() { packageInfoGenerateEnable = true; } + //endregion === 启用配置 === - // === 禁用配置 === + //region === 禁用配置 === public void disableEntity() { entityGenerateEnable = false; @@ -264,9 +270,9 @@ public class GlobalConfig implements Serializable { public void disablePackageInfo() { packageInfoGenerateEnable = false; } + //endregion === 禁用配置 === - - // === 自定义配置 === + //region === 自定义配置 === public Object getCustomConfig(String key) { return customConfig.get(key); @@ -283,7 +289,9 @@ public class GlobalConfig implements Serializable { public void setCustomConfig(Map customConfig) { this.customConfig = customConfig; } - // === 分项配置 === + //endregion === 自定义配置 === + + //region === 分项配置 === /** * @see JavadocConfig#getAuthor() @@ -1566,5 +1574,5 @@ public class GlobalConfig implements Serializable { public void setPackageInfoGenerateEnable(boolean packageInfoGenerateEnable) { this.packageInfoGenerateEnable = packageInfoGenerateEnable; } - + //endregion === 分项配置 === } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java index 396938c5..d83b7271 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/BaseMapper.java @@ -74,7 +74,7 @@ public interface BaseMapper { */ int DEFAULT_BATCH_SIZE = 1000; - // === 增(insert) === + //region === 增(insert) === /** * 插入实体类数据,不忽略 {@code null} 值。 @@ -253,8 +253,9 @@ public interface BaseMapper { return update(entity, ignoreNulls); } } + //endregion === 增(insert) === - // === 删(delete) === + //region === 删(delete) === /** * 根据实体主键来删除数据。 @@ -343,8 +344,9 @@ public interface BaseMapper { */ @DeleteProvider(type = EntitySqlProvider.class, method = "deleteByQuery") int deleteByQuery(@Param(FlexConsts.QUERY) QueryWrapper queryWrapper); + //endregion === 删(delete) === - // === 改(update) === + //region === 改(update) === /** * 根据主键来更新数据,若实体类属性数据为 {@code null},该属性不会更新到数据库。 @@ -439,9 +441,9 @@ public interface BaseMapper { */ @UpdateProvider(type = EntitySqlProvider.class, method = "updateByQuery") int updateByQuery(@Param(FlexConsts.ENTITY) T entity, @Param(FlexConsts.IGNORE_NULLS) boolean ignoreNulls, @Param(FlexConsts.QUERY) QueryWrapper queryWrapper); + //endregion === 改(update) === - - // === 查(select) === + //region === 改(update) === /** * 根据实体主键查询数据。 @@ -1264,5 +1266,5 @@ public interface BaseMapper { } return page; } - + //endregion === 改(update) === } diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java index 88198e37..67f8c08a 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/query/QueryMethods.java @@ -35,7 +35,7 @@ public class QueryMethods { private QueryMethods() { } - // === 数学函数 === + //region === 数学函数 === /** * 返回 x 的绝对值。 @@ -680,8 +680,9 @@ public class QueryMethods { public static QueryColumn cot(LambdaGetter columnX) { return new FunctionQueryColumn(COT, LambdaUtil.getQueryColumn(columnX)); } + //endregion === 数学函数 === - // === 字符串函数 === + //region === 字符串函数 === /** * 返回字符串 s 的字符数。 @@ -1181,8 +1182,9 @@ public class QueryMethods { public static QueryColumn findInSet(LambdaGetter columnS1, LambdaGetter columnS2) { return new FunctionQueryColumn(FIND_IN_SET, LambdaUtil.getQueryColumn(columnS1), LambdaUtil.getQueryColumn(columnS2)); } + //endregion === 字符串函数 === - // === 日期时间函数 === + //region === 日期时间函数 === /** * 返回当前日期。 @@ -1884,8 +1886,9 @@ public class QueryMethods { public static QueryColumn getFormat(LambdaGetter columnType, LambdaGetter columnS) { return new FunctionQueryColumn(GET_FORMAT, LambdaUtil.getQueryColumn(columnType), LambdaUtil.getQueryColumn(columnS)); } + //endregion === 日期时间函数 === - // === 系统信息函数 === + //region === 系统信息函数 === /** * 返回数据库的版本号。 @@ -1970,8 +1973,9 @@ public class QueryMethods { public static QueryColumn lastInsertId() { return new FunctionQueryColumn(LAST_INSERT_ID); } + //endregion === 系统信息函数 === - // === 加密函数 === + //region === 加密函数 === /** * 对字符串 str 进行加密。 @@ -2056,8 +2060,9 @@ public class QueryMethods { public static QueryColumn decode(LambdaGetter columnCryptStr, LambdaGetter

columnPswdStr) { return new FunctionQueryColumn(DECODE, LambdaUtil.getQueryColumn(columnCryptStr), LambdaUtil.getQueryColumn(columnPswdStr)); } + //endregion === 加密函数 === - // === 其他函数 === + //region === 其他函数 === /** * 格式化函数,可以将数字 x 进行格式化,将 x 保留到小数点后 n 位,这个过程需要进行四舍五入。 @@ -2226,8 +2231,9 @@ public class QueryMethods { public static QueryColumn inetNtoa(LambdaGetter columnN) { return new FunctionQueryColumn(INET_NTOA, LambdaUtil.getQueryColumn(columnN)); } + //endregion === 其他函数 === - // === 聚合函数 === + //region === 聚合函数 === /** * 返回指定列的最大值。 @@ -2312,8 +2318,9 @@ public class QueryMethods { public static FunctionQueryColumn sum(LambdaGetter column) { return new FunctionQueryColumn(SUM, LambdaUtil.getQueryColumn(column)); } + //endregion === 聚合函数 === - // === COUNT === + //region === COUNT === /** * 返回指定列的总行数。 @@ -2342,9 +2349,9 @@ public class QueryMethods { public static FunctionQueryColumn count(LambdaGetter column) { return new FunctionQueryColumn(COUNT, LambdaUtil.getQueryColumn(column)); } + //endregion === COUNT === - - // === DISTINCT === + //region === DISTINCT === /** * 对指定列进行去重。 @@ -2358,8 +2365,9 @@ public class QueryMethods { return new DistinctQueryColumn(Arrays.stream(columns) .map(LambdaUtil::getQueryColumn).toArray(QueryColumn[]::new)); } + //endregion === DISTINCT === - // === CASE THEN ELSE === + //region === CASE THEN ELSE === /** * 构建 case then when 语句。 @@ -2374,8 +2382,9 @@ public class QueryMethods { public static CaseSearchQueryColumn.Builder case_(QueryColumn column) { return new CaseSearchQueryColumn.Builder(column); } + //endregion === CASE THEN ELSE === - // === CONVERT === + //region === CONVERT === /** * 将所给类型类型转换为另一种类型。 @@ -2383,8 +2392,9 @@ public class QueryMethods { public static StringFunctionQueryColumn convert(String... params) { return new StringFunctionQueryColumn(CONVERT, params); } + //endregion === CONVERT === - // === 构建 column 列 === + //region === 构建 column 列 === /** * 构建 TRUE 常量。 @@ -2494,8 +2504,9 @@ public class QueryMethods { } return queryColumns; } + //endregion === 构建 column 列 === - // === IF 函数 === + //region === IF 函数 === /** * IF 函数。 @@ -2552,9 +2563,9 @@ public class QueryMethods { public static QueryColumn ifNull(LambdaGetter nullColumn, String elseColumn) { return ifNull(nullColumn, new QueryColumn(elseColumn)); } + //endregion === IF 函数 === - - // === 构建 QueryCondition 查询条件 === + //region === 构建 QueryCondition 查询条件 === /** * EXIST (SELECT ...) @@ -2597,8 +2608,9 @@ public class QueryMethods { public static QueryCondition bracket(QueryCondition condition) { return new Brackets(condition); } + //endregion === 构建 QueryCondition 查询条件 === - // === 构建 QueryWrapper 查询 === + //region === 构建 QueryWrapper 查询 === /** * SELECT queryColumns FROM table @@ -2673,5 +2685,5 @@ public class QueryMethods { public static FunctionQueryColumn date(QueryColumn column) { return new FunctionQueryColumn("DATE", column); } - + //endregion === 构建 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 830bf816..81a85761 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 @@ -51,7 +51,7 @@ public interface IService { */ BaseMapper getMapper(); - // ===== 保存(增)操作 ===== + //region ===== 保存(增)操作 ===== /** *

保存实体类对象数据。 @@ -128,8 +128,9 @@ public interface IService { Class> usefulClass = (Class>) ClassUtil.getUsefulClass(getMapper().getClass()); return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, BaseMapper::insertOrUpdateSelective)); } + //endregion ===== 保存(增)操作 ===== - // ===== 删除(删)操作 ===== + //region ===== 删除(删)操作 ===== /** *

根据查询条件删除数据。 @@ -197,8 +198,9 @@ public interface IService { } return remove(query().where(query)); } + //endregion ===== 删除(删)操作 ===== - // ===== 更新(改)操作 ===== + //region ===== 更新(改)操作 ===== /** *

根据数据主键更新数据。 @@ -313,8 +315,9 @@ public interface IService { Class> usefulClass = (Class>) ClassUtil.getUsefulClass(getMapper().getClass()); return SqlUtil.toBool(Db.executeBatch(entities, batchSize, usefulClass, (mapper, entity) -> mapper.update(entity, ignoreNulls))); } + //endregion ===== 更新(改)操作 ===== - // ===== 查询(查)操作 ===== + //region ===== 查询(查)操作 ===== /** *

根据数据主键查询一条数据。 @@ -546,8 +549,9 @@ public interface IService { default List listByMap(Map query) { return list(query().where(query)); } + //endregion ===== 查询(查)操作 ===== - // ===== 数量查询操作 ===== + //region ===== 数量查询操作 ===== /** *

根据查询条件判断数据是否存在。 @@ -605,8 +609,9 @@ public interface IService { default long count(QueryCondition condition) { return count(query().where(condition)); } + //endregion ===== 数量查询操作 ===== - // ===== 分页查询操作 ===== + //region ===== 分页查询操作 ===== /** *

分页查询所有数据。 @@ -651,8 +656,9 @@ public interface IService { default Page pageAs(Page page, QueryWrapper query, Class asType) { return getMapper().paginateAs(page, query, asType); } + //endregion ===== 分页查询操作 ===== - // ===== 查询包装器操作 ===== + //region ===== 查询包装器操作 ===== /** * 默认 {@link QueryWrapper} 构建。 @@ -680,5 +686,5 @@ public interface IService { default UpdateChain updateChain() { return UpdateChain.create(getMapper()); } - + //endregion ===== 查询包装器操作 ===== }