templates.crud.controller.ftl Maven / Gradle / Ivy
package ${cfg.packageName}.service.${cfg.folderName}.controller;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.yes.tools.page.CommonPage;
import ${cfg.packageName}.common.page.PageParam;
import org.yes.tools.core.result.CommonResult;
import ${cfg.packageName}.common.entity.${cfg.folderName}.${entity};
import ${cfg.packageName}.common.dto.${cfg.folderName}.${entity?replace('Entity','Dto')};
import ${cfg.packageName}.common.vo.${cfg.folderName}.${entity?replace('Entity','Vo')};
import ${cfg.packageName}.service.${cfg.folderName}.service.${table.serviceName};
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
/**
*
* ${table.comment!}
*
* @author ${author}
* @since ${date}
*/
@Slf4j
@Tag(name = "${table.comment!}控制器")
@RestController(value = "${cfg.folderName}${table.controllerName}")
public class ${table.controllerName} {
@Resource
private ${table.serviceName} ${table.serviceName ? uncap_first};
<#if !cfg.isView>
@Operation(summary = "创建")
@PostMapping("<#if !cfg.isSpringCloud>/api#if>/${cfg.folderName}/${package.ModuleName}/create")
public CommonResult<${entity?replace('Entity','Vo')}> create(@Valid @RequestBody ${entity?replace('Entity','Dto')} ${entity?replace('Entity','Dto') ? uncap_first}) {
${entity?replace('Entity','Vo')} ${entity?replace('Entity','Vo') ? uncap_first} = ${table.serviceName ? uncap_first}.create(${entity?replace('Entity','Dto') ? uncap_first});
return CommonResult.success(${entity?replace('Entity','Vo') ? uncap_first});
}
@Operation(summary = "修改")
@PostMapping("<#if !cfg.isSpringCloud>/api#if>/${cfg.folderName}/${package.ModuleName}/modify")
public CommonResult<${entity?replace('Entity','Vo')}> modify(@Valid @RequestBody ${entity?replace('Entity','Dto')} ${entity?replace('Entity','Dto') ? uncap_first}) {
${entity?replace('Entity','Vo')} ${entity?replace('Entity','Vo') ? uncap_first} = ${table.serviceName ? uncap_first}.editById(${entity?replace('Entity','Dto') ? uncap_first});
return CommonResult.success(${entity?replace('Entity','Vo') ? uncap_first});
}
@Operation(summary = "查询详情")
@GetMapping("<#if !cfg.isSpringCloud>/api#if>/${cfg.folderName}/${package.ModuleName}/detail/{id}")
public CommonResult<${entity?replace('Entity','Vo')}> detail(@PathVariable(name = "id") Long id) {
${entity?replace('Entity','Vo')} ${entity?replace('Entity','Vo') ? uncap_first} = ${table.serviceName ? uncap_first}.findById(id);
return CommonResult.success(${entity?replace('Entity','Vo') ? uncap_first});
}
#if>
@Operation(summary = "分页查询")
@GetMapping("<#if !cfg.isSpringCloud>/api#if>/${cfg.folderName}/${package.ModuleName}/query")
public CommonResult> queryByPage(@Validated PageParam pageParam,${entity?replace('Entity','Dto')} dto) {
IPage<${entity?replace('Entity','Vo')}> ${entity?replace('Entity','VoPage') ? uncap_first} = ${table.serviceName ? uncap_first}.queryByPage(pageParam, dto);
return CommonResult.success(CommonPage.restPage(${entity?replace('Entity','VoPage') ? uncap_first}));
}
<#if !cfg.isView>
@Operation(summary = "删除")
@GetMapping("<#if !cfg.isSpringCloud>/api#if>/${cfg.folderName}/${package.ModuleName}/remove/{id}")
public CommonResult delete(@PathVariable(name = "id") Long id) {
return CommonResult.success( ${table.serviceName ? uncap_first}.removeById(id));
}
#if>
}