refactor(codegen): 优化代码生成模板

- 将 API路径和权限标识改为使用 kebab-case 风格- 优化了部分代码注释和命名
- 优化代码生成的注释,增加返回值解释
This commit is contained in:
Theo
2025-04-02 15:21:55 +08:00
parent ded1a527ea
commit abb67a0bf9
7 changed files with 29 additions and 25 deletions

View File

@@ -225,7 +225,7 @@ public class CodegenServiceImpl implements CodegenService {
bindMap.put("tableName", genConfig.getTableName()); bindMap.put("tableName", genConfig.getTableName());
bindMap.put("author", genConfig.getAuthor()); bindMap.put("author", genConfig.getAuthor());
bindMap.put("lowerFirstEntityName", StrUtil.lowerFirst(entityName)); // UserTest → userTest 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("businessName", genConfig.getBusinessName());
bindMap.put("fieldConfigs", fieldConfigs); bindMap.put("fieldConfigs", fieldConfigs);

View File

@@ -1,6 +1,6 @@
import request from "@/utils/request"; 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 = { const ${entityName}API = {
/** 获取${businessName}分页数据 */ /** 获取${businessName}分页数据 */
@@ -24,7 +24,11 @@ const ${entityName}API = {
}); });
}, },
/** 添加${businessName}*/ /**
* 添加${businessName}
*
* @param data ${businessName}表单数据
*/
add(data: ${entityName}Form) { add(data: ${entityName}Form) {
return request({ return request({
url: `${${entityName.toUpperCase()}_BASE_URL}`, url: `${${entityName.toUpperCase()}_BASE_URL}`,

View File

@@ -26,7 +26,7 @@ import jakarta.validation.Valid;
*/ */
@Tag(name = "${businessName}接口") @Tag(name = "${businessName}接口")
@RestController @RestController
@RequestMapping("/api/v1/${lowerFirstEntityName}s") @RequestMapping("/api/v1/${kebabCaseEntityName}")
@RequiredArgsConstructor @RequiredArgsConstructor
public class ${entityName}Controller { public class ${entityName}Controller {
@@ -34,7 +34,7 @@ public class ${entityName}Controller {
@Operation(summary = "$!{businessName}分页列表") @Operation(summary = "$!{businessName}分页列表")
@GetMapping("/page") @GetMapping("/page")
@PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:query')") @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:query')")
public PageResult<${entityName}VO> get${entityName}Page(${entityName}Query queryParams ) { public PageResult<${entityName}VO> get${entityName}Page(${entityName}Query queryParams ) {
IPage<${entityName}VO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams); IPage<${entityName}VO> result = ${lowerFirstEntityName}Service.get${entityName}Page(queryParams);
return PageResult.success(result); return PageResult.success(result);
@@ -42,7 +42,7 @@ public class ${entityName}Controller {
@Operation(summary = "新增${businessName}") @Operation(summary = "新增${businessName}")
@PostMapping @PostMapping
@PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:add')") @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:add')")
public Result<Void> save${entityName}(@RequestBody @Valid ${entityName}Form formData ) { public Result<Void> save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData); boolean result = ${lowerFirstEntityName}Service.save${entityName}(formData);
return Result.judge(result); return Result.judge(result);
@@ -50,7 +50,7 @@ public class ${entityName}Controller {
@Operation(summary = "获取${businessName}表单数据") @Operation(summary = "获取${businessName}表单数据")
@GetMapping("/{id}/form") @GetMapping("/{id}/form")
@PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:edit')") @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:edit')")
public Result<${entityName}Form> get${entityName}Form( public Result<${entityName}Form> get${entityName}Form(
@Parameter(description = "$!{businessName}ID") @PathVariable Long id @Parameter(description = "$!{businessName}ID") @PathVariable Long id
) { ) {
@@ -60,7 +60,7 @@ public class ${entityName}Controller {
@Operation(summary = "修改${businessName}") @Operation(summary = "修改${businessName}")
@PutMapping(value = "/{id}") @PutMapping(value = "/{id}")
@PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:edit')") @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:edit')")
public Result<Void> update${entityName}( public Result<Void> update${entityName}(
@Parameter(description = "$!{businessName}ID") @PathVariable Long id, @Parameter(description = "$!{businessName}ID") @PathVariable Long id,
@RequestBody @Validated ${entityName}Form formData @RequestBody @Validated ${entityName}Form formData
@@ -71,7 +71,7 @@ public class ${entityName}Controller {
@Operation(summary = "删除${businessName}") @Operation(summary = "删除${businessName}")
@DeleteMapping("/{ids}") @DeleteMapping("/{ids}")
@PreAuthorize("@ss.hasPerm('${moduleName}:${lowerFirstEntityName}:delete')") @PreAuthorize("@ss.hasPerm('${moduleName}:${kebabCaseEntityName}:delete')")
public Result<Void> delete${entityName}s( public Result<Void> delete${entityName}s(
@Parameter(description = "$!{businessName}ID多个以英文逗号(,)分割") @PathVariable String ids @Parameter(description = "$!{businessName}ID多个以英文逗号(,)分割") @PathVariable String ids
) { ) {

View File

@@ -104,7 +104,7 @@
<el-card shadow="never"> <el-card shadow="never">
<div class="mb-10px"> <div class="mb-10px">
<el-button <el-button
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:add']" v-hasPerm="['${moduleName}:${kebabCaseEntityName}:add']"
type="success" type="success"
@click="handleOpenDialog()" @click="handleOpenDialog()"
> >
@@ -112,7 +112,7 @@
新增 新增
</el-button> </el-button>
<el-button <el-button
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:delete']" v-hasPerm="['${moduleName}:${kebabCaseEntityName}:delete']"
type="danger" type="danger"
:disabled="removeIds.length === 0" :disabled="removeIds.length === 0"
@click="handleDelete()" @click="handleDelete()"
@@ -153,7 +153,7 @@
<el-table-column fixed="right" label="操作" width="220"> <el-table-column fixed="right" label="操作" width="220">
<template #default="scope"> <template #default="scope">
<el-button <el-button
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:edit']" v-hasPerm="['${moduleName}:${kebabCaseEntityName}:edit']"
type="primary" type="primary"
size="small" size="small"
link link
@@ -163,7 +163,7 @@
编辑 编辑
</el-button> </el-button>
<el-button <el-button
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:delete']" v-hasPerm="['${moduleName}:${kebabCaseEntityName}:delete']"
type="danger" type="danger"
size="small" size="small"
link link
@@ -285,8 +285,8 @@
import ${entityName}API, { ${entityName}PageVO, ${entityName}Form, ${entityName}PageQuery } from "@/api/${moduleName}/${kebabCaseEntityName}"; import ${entityName}API, { ${entityName}PageVO, ${entityName}Form, ${entityName}PageQuery } from "@/api/${moduleName}/${kebabCaseEntityName}";
const queryFormRef = ref(ElForm); const queryFormRef = ref();
const dataFormRef = ref(ElForm); const dataFormRef = ref();
const loading = ref(false); const loading = ref(false);
const removeIds = ref<number[]>([]); const removeIds = ref<number[]>([]);

View File

@@ -21,7 +21,7 @@ public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
* *
* @param page 分页对象 * @param page 分页对象
* @param queryParams 查询参数 * @param queryParams 查询参数
* @return * @return {@link Page<${entityName}VO>} $!{businessName}分页列表
*/ */
Page<${entityName}VO> get${entityName}Page(Page<${entityName}VO> page, ${entityName}Query queryParams); Page<${entityName}VO> get${entityName}Page(Page<${entityName}VO> page, ${entityName}Query queryParams);

View File

@@ -18,7 +18,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
/** /**
*$!{businessName}分页列表 *$!{businessName}分页列表
* *
* @return * @return {@link IPage<${entityName}VO>} $!{businessName}分页列表
*/ */
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams); IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
@@ -26,7 +26,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
* 获取${businessName}表单数据 * 获取${businessName}表单数据
* *
* @param id $!{businessName}ID * @param id $!{businessName}ID
* @return * @return ${businessName}表单数据
*/ */
${entityName}Form get${entityName}FormData(Long id); ${entityName}Form get${entityName}FormData(Long id);
@@ -34,7 +34,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
* 新增${businessName} * 新增${businessName}
* *
* @param formData $!{businessName}表单对象 * @param formData $!{businessName}表单对象
* @return * @return 是否新增成功
*/ */
boolean save${entityName}(${entityName}Form formData); boolean save${entityName}(${entityName}Form formData);
@@ -43,7 +43,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
* *
* @param id $!{businessName}ID * @param id $!{businessName}ID
* @param formData $!{businessName}表单对象 * @param formData $!{businessName}表单对象
* @return * @return 是否修改成功
*/ */
boolean update${entityName}(Long id, ${entityName}Form formData); boolean update${entityName}(Long id, ${entityName}Form formData);
@@ -51,7 +51,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
* 删除${businessName} * 删除${businessName}
* *
* @param ids $!{businessName}ID多个以英文逗号(,)分割 * @param ids $!{businessName}ID多个以英文逗号(,)分割
* @return * @return 是否删除成功
*/ */
boolean delete${entityName}s(String ids); boolean delete${entityName}s(String ids);

View File

@@ -51,7 +51,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
* 获取${businessName}表单数据 * 获取${businessName}表单数据
* *
* @param id $!{businessName}ID * @param id $!{businessName}ID
* @return * @return ${businessName}表单数据
*/ */
@Override @Override
public ${entityName}Form get${entityName}FormData(Long id) { public ${entityName}Form get${entityName}FormData(Long id) {
@@ -63,7 +63,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
* 新增${businessName} * 新增${businessName}
* *
* @param formData $!{businessName}表单对象 * @param formData $!{businessName}表单对象
* @return * @return 是否新增成功
*/ */
@Override @Override
public boolean save${entityName}(${entityName}Form formData) { public boolean save${entityName}(${entityName}Form formData) {
@@ -76,7 +76,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
* *
* @param id $!{businessName}ID * @param id $!{businessName}ID
* @param formData $!{businessName}表单对象 * @param formData $!{businessName}表单对象
* @return * @return 是否修改成功
*/ */
@Override @Override
public boolean update${entityName}(Long id,${entityName}Form formData) { public boolean update${entityName}(Long id,${entityName}Form formData) {
@@ -88,7 +88,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
* 删除${businessName} * 删除${businessName}
* *
* @param ids $!{businessName}ID多个以英文逗号(,)分割 * @param ids $!{businessName}ID多个以英文逗号(,)分割
* @return * @return 是否删除成功
*/ */
@Override @Override
public boolean delete${entityName}s(String ids) { public boolean delete${entityName}s(String ids) {