diff --git a/README.md b/README.md index 42051154..ddc71c62 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Sonar Status -ContiNew Starter +ContiNew Starter Spring Boot @@ -216,7 +216,7 @@ public class DeptController extends BaseControllerArco Design | 2.56.0 | 字节跳动推出的前端 UI 框架,年轻化的色彩和组件设计。 | | TypeScript | 5.0.4 | TypeScript 是微软开发的一个开源的编程语言,通过在 JavaScript 的基础上添加静态类型定义构建而成。 | | Vite | 5.1.5 | 下一代的前端工具链,为开发提供极速响应。 | -| [ContiNew Starter](https://github.com/continew-org/continew-starter) | 2.7.2 | ContiNew Starter 包含了一系列经过企业实践优化的依赖包(如 MyBatis-Plus、SaToken),可轻松集成到应用中,为开发人员减少手动引入依赖及配置的麻烦,为 Spring Boot Web 项目的灵活快速构建提供支持。 | +| [ContiNew Starter](https://github.com/continew-org/continew-starter) | 2.7.3 | ContiNew Starter 包含了一系列经过企业实践优化的依赖包(如 MyBatis-Plus、SaToken),可轻松集成到应用中,为开发人员减少手动引入依赖及配置的麻烦,为 Spring Boot Web 项目的灵活快速构建提供支持。 | | Spring Boot | 3.2.10 | 简化 Spring 应用的初始搭建和开发过程,基于“约定优于配置”的理念,使开发人员不再需要定义样板化的配置。(Spring Boot 3.0 开始,要求 Java 17 作为最低版本) | | Undertow | 2.3.13.Final | 采用 Java 开发的灵活的高性能 Web 服务器,提供包括阻塞和基于 NIO 的非堵塞机制。 | | Sa-Token + JWT | 1.39.0 | 轻量级 Java 权限认证框架,让鉴权变得简单、优雅。 | diff --git a/continew-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java b/continew-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java index 382682a7..f2f7562d 100644 --- a/continew-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java +++ b/continew-common/src/main/java/top/continew/admin/common/config/exception/GlobalExceptionHandler.java @@ -24,6 +24,7 @@ import org.springframework.core.annotation.Order; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ExceptionHandler; import org.springframework.web.bind.annotation.RestControllerAdvice; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; import org.springframework.web.multipart.MultipartException; import top.continew.starter.core.exception.BadRequestException; import top.continew.starter.core.exception.BusinessException; @@ -58,6 +59,16 @@ public class GlobalExceptionHandler { return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), e.getMessage()); } + /** + * 拦截校验异常-方法参数类型不匹配异常 + */ + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + public R handleMethodArgumentTypeMismatchException(MethodArgumentTypeMismatchException e, + HttpServletRequest request) { + log.error("[{}] {}", request.getMethod(), request.getRequestURI(), e); + return R.fail(String.valueOf(HttpStatus.BAD_REQUEST.value()), "参数 '%s' 类型不匹配".formatted(e.getName())); + } + /** * 拦截文件上传异常-超过上传大小限制 */ diff --git a/continew-module-system/src/main/java/top/continew/admin/system/config/mail/MailConfigurerImpl.java b/continew-module-system/src/main/java/top/continew/admin/system/config/mail/MailConfigurerImpl.java index bc0ac3e8..e7deec96 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/config/mail/MailConfigurerImpl.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/config/mail/MailConfigurerImpl.java @@ -21,6 +21,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import top.continew.admin.common.constant.SysConstants; +import top.continew.admin.system.enums.OptionCategoryEnum; import top.continew.admin.system.service.OptionService; import top.continew.starter.messaging.mail.core.MailConfig; import top.continew.starter.messaging.mail.core.MailConfigurer; @@ -43,7 +44,7 @@ public class MailConfigurerImpl implements MailConfigurer { @Override public MailConfig getMailConfig() { // 查询邮件配置 - Map map = optionService.getByCategory("MAIL"); + Map map = optionService.getByCategory(OptionCategoryEnum.MAIL); // 封装邮件配置 MailConfig mailConfig = new MailConfig(); mailConfig.setProtocol(MapUtil.getStr(map, "MAIL_PROTOCOL")); diff --git a/continew-module-system/src/main/java/top/continew/admin/system/enums/PasswordPolicyEnum.java b/continew-module-system/src/main/java/top/continew/admin/system/enums/PasswordPolicyEnum.java index 03e8cadc..ebfbb50f 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/enums/PasswordPolicyEnum.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/enums/PasswordPolicyEnum.java @@ -168,7 +168,7 @@ public enum PasswordPolicyEnum { /** * 策略类别 */ - public static final String CATEGORY = "PASSWORD"; + public static final OptionCategoryEnum CATEGORY = OptionCategoryEnum.PASSWORD; /** * 校验取值范围 diff --git a/continew-module-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java b/continew-module-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java index ecbfc85d..8da78209 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/model/query/OptionQuery.java @@ -19,6 +19,7 @@ package top.continew.admin.system.model.query; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import top.continew.admin.system.enums.OptionCategoryEnum; +import top.continew.starter.core.validation.constraints.EnumValue; import top.continew.starter.data.core.annotation.Query; import top.continew.starter.data.core.enums.QueryType; @@ -50,5 +51,6 @@ public class OptionQuery implements Serializable { * 类别 */ @Schema(description = "类别", example = "SITE") - private OptionCategoryEnum category; + @EnumValue(value = OptionCategoryEnum.class, message = "类别非法") + private String category; } \ No newline at end of file diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/OptionService.java b/continew-module-system/src/main/java/top/continew/admin/system/service/OptionService.java index c0d9730b..90982f01 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/OptionService.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/OptionService.java @@ -16,6 +16,7 @@ package top.continew.admin.system.service; +import top.continew.admin.system.enums.OptionCategoryEnum; import top.continew.admin.system.model.query.OptionQuery; import top.continew.admin.system.model.req.OptionReq; import top.continew.admin.system.model.req.OptionResetValueReq; @@ -47,7 +48,7 @@ public interface OptionService { * @param category 类别 * @return 参数信息 */ - Map getByCategory(String category); + Map getByCategory(OptionCategoryEnum category); /** * 修改参数 diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java index f2a6240e..95530b76 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/OptionServiceImpl.java @@ -26,6 +26,7 @@ import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWra import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import top.continew.admin.common.constant.CacheConstants; +import top.continew.admin.system.enums.OptionCategoryEnum; import top.continew.admin.system.enums.PasswordPolicyEnum; import top.continew.admin.system.mapper.OptionMapper; import top.continew.admin.system.model.entity.OptionDO; @@ -64,8 +65,8 @@ public class OptionServiceImpl implements OptionService { @Override @Cached(key = "#category", name = CacheConstants.OPTION_KEY_PREFIX + "MAP:") - public Map getByCategory(String category) { - return baseMapper.selectByCategory(category) + public Map getByCategory(OptionCategoryEnum category) { + return baseMapper.selectByCategory(category.name()) .stream() .collect(Collectors.toMap(OptionDO::getCode, o -> StrUtil.emptyIfNull(ObjectUtil.defaultIfNull(o .getValue(), o.getDefaultValue())), (oldVal, newVal) -> oldVal)); @@ -87,8 +88,8 @@ public class OptionServiceImpl implements OptionService { } // 校验密码策略参数取值范围 Map passwordPolicyOptionMap = options.stream() - .filter(option -> StrUtil.startWith(option - .getCode(), PasswordPolicyEnum.CATEGORY + StringConstants.UNDERLINE)) + .filter(option -> StrUtil.startWith(option.getCode(), PasswordPolicyEnum.CATEGORY + .name() + StringConstants.UNDERLINE)) .collect(Collectors.toMap(OptionReq::getCode, OptionReq::getValue, (oldVal, newVal) -> oldVal)); for (Map.Entry passwordPolicyOptionEntry : passwordPolicyOptionMap.entrySet()) { String code = passwordPolicyOptionEntry.getKey(); diff --git a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java index 13702bd1..aa48bdc6 100644 --- a/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java +++ b/continew-module-system/src/main/java/top/continew/admin/system/service/impl/UserServiceImpl.java @@ -61,6 +61,7 @@ import top.continew.admin.common.context.UserContextHolder; import top.continew.admin.common.enums.DisEnableStatusEnum; import top.continew.admin.common.enums.GenderEnum; import top.continew.admin.common.util.SecureUtils; +import top.continew.admin.system.enums.OptionCategoryEnum; import top.continew.admin.system.mapper.UserMapper; import top.continew.admin.system.model.entity.DeptDO; import top.continew.admin.system.model.entity.RoleDO; @@ -630,7 +631,7 @@ public class UserServiceImpl extends BaseServiceImpl passwordPolicy = optionService.getByCategory(CATEGORY); + Map passwordPolicy = optionService.getByCategory(OptionCategoryEnum.PASSWORD); // 密码最小长度 PASSWORD_MIN_LENGTH.validate(password, MapUtil.getInt(passwordPolicy, PASSWORD_MIN_LENGTH.name()), user); // 密码是否必须包含特殊字符 diff --git a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java index cc83f0e1..06833843 100644 --- a/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java +++ b/continew-plugin/continew-plugin-generator/src/main/java/top/continew/admin/generator/model/entity/GenConfigDO.java @@ -26,7 +26,7 @@ import lombok.Data; import lombok.NoArgsConstructor; import org.hibernate.validator.constraints.Length; import top.continew.admin.common.constant.RegexConstants; -import top.continew.starter.core.constant.StringConstants; +import top.continew.starter.core.constant.CharConstants; import top.continew.starter.core.util.StrUtils; import java.io.Serial; @@ -130,7 +130,7 @@ public class GenConfigDO implements Serializable { public void setTableName(String tableName) { this.tableName = tableName; // 默认表前缀(sys_user -> sys_) - int underLineIndex = StrUtil.indexOf(tableName, StringConstants.C_UNDERLINE); + int underLineIndex = StrUtil.indexOf(tableName, CharConstants.UNDERLINE); if (-1 != underLineIndex) { this.tablePrefix = StrUtil.subPre(tableName, underLineIndex + 1); } diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Controller.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Controller.ftl index 80b578e0..60172f51 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Controller.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/backend/Controller.ftl @@ -22,5 +22,5 @@ import ${packageName}.service.${classNamePrefix}Service; */ @Tag(name = "${businessName}管理 API") @RestController -@CrudRequestMapping(value = "/${apiModuleName}/${apiName}", api = {Api.PAGE, Api.GET, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT}) +@CrudRequestMapping(value = "/${apiModuleName}/${apiName}", api = {Api.PAGE, Api.DETAIL, Api.ADD, Api.UPDATE, Api.DELETE, Api.EXPORT}) public class ${className} extends BaseController<${classNamePrefix}Service, ${classNamePrefix}Resp, ${classNamePrefix}DetailResp, ${classNamePrefix}Query, ${classNamePrefix}Req> {} \ No newline at end of file diff --git a/continew-plugin/continew-plugin-generator/src/main/resources/templates/frontend/AddModal.ftl b/continew-plugin/continew-plugin-generator/src/main/resources/templates/frontend/AddModal.ftl index aa452a91..0474b8ea 100644 --- a/continew-plugin/continew-plugin-generator/src/main/resources/templates/frontend/AddModal.ftl +++ b/continew-plugin/continew-plugin-generator/src/main/resources/templates/frontend/AddModal.ftl @@ -14,6 +14,7 @@