refactor(codegen): 优化代码生成模板
- 将 API路径和权限标识改为使用 kebab-case 风格- 优化了部分代码注释和命名 - 优化代码生成的注释,增加返回值解释
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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}`,
|
||||
|
||||
@@ -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<Void> 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<Void> 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<Void> delete${entityName}s(
|
||||
@Parameter(description = "$!{businessName}ID,多个以英文逗号(,)分割") @PathVariable String ids
|
||||
) {
|
||||
|
||||
@@ -104,7 +104,7 @@
|
||||
<el-card shadow="never">
|
||||
<div class="mb-10px">
|
||||
<el-button
|
||||
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:add']"
|
||||
v-hasPerm="['${moduleName}:${kebabCaseEntityName}:add']"
|
||||
type="success"
|
||||
@click="handleOpenDialog()"
|
||||
>
|
||||
@@ -112,7 +112,7 @@
|
||||
新增
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:delete']"
|
||||
v-hasPerm="['${moduleName}:${kebabCaseEntityName}:delete']"
|
||||
type="danger"
|
||||
:disabled="removeIds.length === 0"
|
||||
@click="handleDelete()"
|
||||
@@ -153,7 +153,7 @@
|
||||
<el-table-column fixed="right" label="操作" width="220">
|
||||
<template #default="scope">
|
||||
<el-button
|
||||
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:edit']"
|
||||
v-hasPerm="['${moduleName}:${kebabCaseEntityName}:edit']"
|
||||
type="primary"
|
||||
size="small"
|
||||
link
|
||||
@@ -163,7 +163,7 @@
|
||||
编辑
|
||||
</el-button>
|
||||
<el-button
|
||||
v-hasPerm="['${moduleName}:${lowerFirstEntityName}:delete']"
|
||||
v-hasPerm="['${moduleName}:${kebabCaseEntityName}:delete']"
|
||||
type="danger"
|
||||
size="small"
|
||||
link
|
||||
@@ -285,8 +285,8 @@
|
||||
|
||||
import ${entityName}API, { ${entityName}PageVO, ${entityName}Form, ${entityName}PageQuery } from "@/api/${moduleName}/${kebabCaseEntityName}";
|
||||
|
||||
const queryFormRef = ref(ElForm);
|
||||
const dataFormRef = ref(ElForm);
|
||||
const queryFormRef = ref();
|
||||
const dataFormRef = ref();
|
||||
|
||||
const loading = ref(false);
|
||||
const removeIds = ref<number[]>([]);
|
||||
|
||||
@@ -21,7 +21,7 @@ public interface ${entityName}Mapper extends BaseMapper<${entityName}> {
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param queryParams 查询参数
|
||||
* @return
|
||||
* @return {@link Page<${entityName}VO>} $!{businessName}分页列表
|
||||
*/
|
||||
Page<${entityName}VO> get${entityName}Page(Page<${entityName}VO> page, ${entityName}Query queryParams);
|
||||
|
||||
|
||||
@@ -18,7 +18,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
||||
/**
|
||||
*$!{businessName}分页列表
|
||||
*
|
||||
* @return
|
||||
* @return {@link IPage<${entityName}VO>} $!{businessName}分页列表
|
||||
*/
|
||||
IPage<${entityName}VO> get${entityName}Page(${entityName}Query queryParams);
|
||||
|
||||
@@ -26,7 +26,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
||||
* 获取${businessName}表单数据
|
||||
*
|
||||
* @param id $!{businessName}ID
|
||||
* @return
|
||||
* @return ${businessName}表单数据
|
||||
*/
|
||||
${entityName}Form get${entityName}FormData(Long id);
|
||||
|
||||
@@ -34,7 +34,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
||||
* 新增${businessName}
|
||||
*
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
boolean save${entityName}(${entityName}Form formData);
|
||||
|
||||
@@ -43,7 +43,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
||||
*
|
||||
* @param id $!{businessName}ID
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
boolean update${entityName}(Long id, ${entityName}Form formData);
|
||||
|
||||
@@ -51,7 +51,7 @@ public interface ${entityName}Service extends IService<${entityName}> {
|
||||
* 删除${businessName}
|
||||
*
|
||||
* @param ids $!{businessName}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
boolean delete${entityName}s(String ids);
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
* 获取${businessName}表单数据
|
||||
*
|
||||
* @param id $!{businessName}ID
|
||||
* @return
|
||||
* @return ${businessName}表单数据
|
||||
*/
|
||||
@Override
|
||||
public ${entityName}Form get${entityName}FormData(Long id) {
|
||||
@@ -63,7 +63,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
* 新增${businessName}
|
||||
*
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
* @return 是否新增成功
|
||||
*/
|
||||
@Override
|
||||
public boolean save${entityName}(${entityName}Form formData) {
|
||||
@@ -76,7 +76,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
*
|
||||
* @param id $!{businessName}ID
|
||||
* @param formData $!{businessName}表单对象
|
||||
* @return
|
||||
* @return 是否修改成功
|
||||
*/
|
||||
@Override
|
||||
public boolean update${entityName}(Long id,${entityName}Form formData) {
|
||||
@@ -88,7 +88,7 @@ public class ${entityName}ServiceImpl extends ServiceImpl<${entityName}Mapper, $
|
||||
* 删除${businessName}
|
||||
*
|
||||
* @param ids $!{businessName}ID,多个以英文逗号(,)分割
|
||||
* @return
|
||||
* @return 是否删除成功
|
||||
*/
|
||||
@Override
|
||||
public boolean delete${entityName}s(String ids) {
|
||||
|
||||
Reference in New Issue
Block a user