From abb67a0bf9a6f006b410c3aeb44f3ca69bf23817 Mon Sep 17 00:00:00 2001 From: Theo <971366405@qq.com> Date: Wed, 2 Apr 2025 15:21:55 +0800 Subject: [PATCH] =?UTF-8?q?refactor(codegen):=20=E4=BC=98=E5=8C=96?= =?UTF-8?q?=E4=BB=A3=E7=A0=81=E7=94=9F=E6=88=90=E6=A8=A1=E6=9D=BF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 API路径和权限标识改为使用 kebab-case 风格- 优化了部分代码注释和命名 - 优化代码生成的注释,增加返回值解释 --- .../codegen/service/impl/CodegenServiceImpl.java | 2 +- src/main/resources/templates/codegen/api.ts.vm | 8 ++++++-- .../resources/templates/codegen/controller.java.vm | 12 ++++++------ src/main/resources/templates/codegen/index.vue.vm | 12 ++++++------ src/main/resources/templates/codegen/mapper.java.vm | 2 +- src/main/resources/templates/codegen/service.java.vm | 10 +++++----- .../resources/templates/codegen/serviceImpl.java.vm | 8 ++++---- 7 files changed, 29 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/youlai/boot/shared/codegen/service/impl/CodegenServiceImpl.java b/src/main/java/com/youlai/boot/shared/codegen/service/impl/CodegenServiceImpl.java index ea15f6c3..6ae9e04e 100644 --- a/src/main/java/com/youlai/boot/shared/codegen/service/impl/CodegenServiceImpl.java +++ b/src/main/java/com/youlai/boot/shared/codegen/service/impl/CodegenServiceImpl.java @@ -225,7 +225,7 @@ public class CodegenServiceImpl implements CodegenService { bindMap.put("tableName", genConfig.getTableName()); bindMap.put("author", genConfig.getAuthor()); bindMap.put("lowerFirstEntityName", StrUtil.lowerFirst(entityName)); // UserTest → userTest - bindMap.put("kebabCaseEntityName", StrUtil.toSymbolCase(entityName, '-')); // UserTest → user-websocket + bindMap.put("kebabCaseEntityName", StrUtil.toSymbolCase(entityName, '-')); // UserTest → user-test bindMap.put("businessName", genConfig.getBusinessName()); bindMap.put("fieldConfigs", fieldConfigs); diff --git a/src/main/resources/templates/codegen/api.ts.vm b/src/main/resources/templates/codegen/api.ts.vm index cbf8f6dd..afddcc9c 100644 --- a/src/main/resources/templates/codegen/api.ts.vm +++ b/src/main/resources/templates/codegen/api.ts.vm @@ -1,6 +1,6 @@ import request from "@/utils/request"; -const ${entityName.toUpperCase()}_BASE_URL = "/api/v1/${lowerFirstEntityName}s"; +const ${entityName.toUpperCase()}_BASE_URL = "/api/v1/${kebabCaseEntityName}"; const ${entityName}API = { /** 获取${businessName}分页数据 */ @@ -24,7 +24,11 @@ const ${entityName}API = { }); }, - /** 添加${businessName}*/ + /** + * 添加${businessName} + * + * @param data ${businessName}表单数据 + */ add(data: ${entityName}Form) { return request({ url: `${${entityName.toUpperCase()}_BASE_URL}`, diff --git a/src/main/resources/templates/codegen/controller.java.vm b/src/main/resources/templates/codegen/controller.java.vm index 792db37a..21c3b718 100644 --- a/src/main/resources/templates/codegen/controller.java.vm +++ b/src/main/resources/templates/codegen/controller.java.vm @@ -26,7 +26,7 @@ import jakarta.validation.Valid; */ @Tag(name = "${businessName}接口") @RestController -@RequestMapping("/api/v1/${lowerFirstEntityName}s") +@RequestMapping("/api/v1/${kebabCaseEntityName}") @RequiredArgsConstructor public class ${entityName}Controller { @@ -34,7 +34,7 @@ public class ${entityName}Controller { @Operation(summary = "$!{businessName}分页列表") @GetMapping("/page") - @PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:query')") + @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:query')") public PageResult<${entityName}VO> get${entityName}Page(${entityName}Query queryParams ) { IPage<${entityName}VO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams); return PageResult.success(result); @@ -42,7 +42,7 @@ public class ${entityName}Controller { @Operation(summary = "新增${businessName}") @PostMapping - @PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:add')") + @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:add')") public Result save${entityName}(@RequestBody @Valid ${entityName}Form formData ) { boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData); return Result.judge(result); @@ -50,7 +50,7 @@ public class ${entityName}Controller { @Operation(summary = "获取${businessName}表单数据") @GetMapping("/{id}/form") - @PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:edit')") + @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:edit')") public Result<${entityName}Form> get${entityName}Form( @Parameter(description = "$!{businessName}ID") @PathVariable Long id ) { @@ -60,7 +60,7 @@ public class ${entityName}Controller { @Operation(summary = "修改${businessName}") @PutMapping(value = "/{id}") - @PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:edit')") + @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:edit')") public Result update${entityName}( @Parameter(description = "$!{businessName}ID") @PathVariable Long id, @RequestBody @Validated ${entityName}Form formData @@ -71,7 +71,7 @@ public class ${entityName}Controller { @Operation(summary = "删除${businessName}") @DeleteMapping("/{ids}") - @PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:delete')") + @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:delete')") public Result delete${entityName}s( @Parameter(description = "$!{businessName}ID,多个以英文逗号(,)分割") @PathVariable String ids ) { diff --git a/src/main/resources/templates/codegen/index.vue.vm b/src/main/resources/templates/codegen/index.vue.vm index c7bdad55..b7c4021a 100644 --- a/src/main/resources/templates/codegen/index.vue.vm +++ b/src/main/resources/templates/codegen/index.vue.vm @@ -104,7 +104,7 @@
@@ -112,7 +112,7 @@ 新增