Files
youlai-boot/src/main/resources/templates/codegen/backend/controller.java.vm
Theo fa0ab86445 refactor(codegen): 更新后端控制器模板中的导入路径
- 将 PageResult 和 Result 的导入路径从 core.web 更新为 common.result
- 保持其他导入和注解功能不变
- 统一结果类的包结构到 common 模块下
2026-04-10 18:34:14 +08:00

82 lines
3.3 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package ${packageName}.${moduleName}.${subpackageName};
import ${packageName}.${moduleName}.service.${entityName}Service;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ${packageName}.${moduleName}.model.form.${entityName}Form;
import ${packageName}.${moduleName}.model.query.${entityName}Query;
import ${packageName}.${moduleName}.model.vo.${entityName}Vo;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.youlai.boot.common.result.PageResult;
import com.youlai.boot.common.result.Result;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.validation.Valid;
/**
* $!{businessName}前端控制层
*
* @author ${author}
* @since ${date}
*/
@Tag(name = "${businessName}接口")
@RestController
@RequestMapping("/api/v1/${entityKebab}")
@RequiredArgsConstructor
public class ${entityName}Controller {
private final ${entityName}Service ${entityLowerCamel}Service;
@Operation(summary = "$!{businessName}分页列表")
@GetMapping
@PreAuthorize("@ss.hasPerm('${moduleName}:${entityKebab}:list')")
public PageResult<${entityName}Vo> get${entityName}Page(${entityName}Query queryParams ) {
IPage<${entityName}Vo> result = ${entityLowerCamel}Service.get${entityName}Page(queryParams);
return PageResult.success(result);
}
@Operation(summary = "新增${businessName}")
@PostMapping
@PreAuthorize("@ss.hasPerm('${moduleName}:${entityKebab}:create')")
public Result<Void> save${entityName}(@RequestBody @Valid ${entityName}Form formData ) {
boolean result = ${entityLowerCamel}Service.save${entityName}(formData);
return Result.judge(result);
}
@Operation(summary = "获取${businessName}表单数据")
@GetMapping("/{id}/form")
@PreAuthorize("@ss.hasPerm('${moduleName}:${entityKebab}:update')")
public Result<${entityName}Form> get${entityName}Form(
@Parameter(description = "$!{businessName}ID") @PathVariable Long id
) {
${entityName}Form formData = ${entityLowerCamel}Service.get${entityName}FormData(id);
return Result.success(formData);
}
@Operation(summary = "修改${businessName}")
@PutMapping(value = "/{id}")
@PreAuthorize("@ss.hasPerm('${moduleName}:${entityKebab}:update')")
public Result<Void> update${entityName}(
@Parameter(description = "$!{businessName}ID") @PathVariable Long id,
@RequestBody @Validated ${entityName}Form formData
) {
boolean result = ${entityLowerCamel}Service.update${entityName}(id, formData);
return Result.judge(result);
}
@Operation(summary = "删除${businessName}")
@DeleteMapping("/{ids}")
@PreAuthorize("@ss.hasPerm('${moduleName}:${entityKebab}:delete')")
public Result<Void> delete${entityName}s(
@Parameter(description = "$!{businessName}ID多个以英文逗号(,)分割") @PathVariable String ids
) {
boolean result = ${entityLowerCamel}Service.delete${entityName}s(ids);
return Result.judge(result);
}
}