package ${packageName}.${moduleName}.controller; import ${packageName}.${moduleName}.entity.${entityName}; import ${packageName}.${moduleName}.param.${entityName}Param; import ${packageName}.${moduleName}.service.${entityName}Service; import ${packageName}.common.core.web.ApiResult; import ${packageName}.common.core.web.PageResult; import ${packageName}.common.core.web.BaseController; <% if(generateSwagger) { %> import io.swagger.annotations.Api; import io.swagger.annotations.ApiOperation; <% } %> <% if(generateAuth) { %> import org.springframework.security.access.prepost.PreAuthorize; <% } %> <% if(generateLog) { %> import ${packageName}.common.core.annotation.OperationLog; <% } %> import org.springframework.web.bind.annotation.*; import lombok.extern.slf4j.Slf4j; import javax.annotation.Resource; import java.util.List; /** * ${tableComment}控制器 * * @author ${author} * @since ${date()} */ @Slf4j <% if(generateSwagger) { %> @Api(tags = "${tableComment}管理") <% } %> @RestController @RequestMapping("/api/${moduleName}/${entityPath}") public class ${entityName}Controller extends BaseController { @Resource private ${entityName}Service ${entityPath}Service; <% if(generateSwagger) { %> @ApiOperation("分页查询${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:list')") <% } %> @GetMapping("/page") public ApiResult> page(${entityName}Param param) { return success(${entityPath}Service.page(param)); } <% if(generateSwagger) { %> @ApiOperation("查询全部${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:list')") <% } %> @GetMapping public ApiResult> list(${entityName}Param param) { return success(${entityPath}Service.list(param)); } <% if(generateSwagger) { %> @ApiOperation("根据ID查询${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:list')") <% } %> @GetMapping("/{id}") public ApiResult<${entityName}> getById(@PathVariable ${primaryKey.propertyType} id) { return success(${entityPath}Service.getById(id)); } <% if(generateSwagger) { %> @ApiOperation("新增${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:save')") <% } %> <% if(generateLog) { %> @OperationLog <% } %> @PostMapping public ApiResult save(@RequestBody ${entityName} ${entityPath}) { if (${entityPath}Service.save(${entityPath})) { return success("新增成功"); } return error("新增失败"); } <% if(generateSwagger) { %> @ApiOperation("修改${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:update')") <% } %> <% if(generateLog) { %> @OperationLog <% } %> @PutMapping public ApiResult update(@RequestBody ${entityName} ${entityPath}) { if (${entityPath}Service.updateById(${entityPath})) { return success("修改成功"); } return error("修改失败"); } <% if(generateSwagger) { %> @ApiOperation("删除${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:remove')") <% } %> <% if(generateLog) { %> @OperationLog <% } %> @DeleteMapping("/{id}") public ApiResult remove(@PathVariable ${primaryKey.propertyType} id) { if (${entityPath}Service.removeById(id)) { return success("删除成功"); } return error("删除失败"); } <% if(generateSwagger) { %> @ApiOperation("批量删除${tableComment}") <% } %> <% if(generateAuth) { %> @PreAuthorize("hasAuthority('${moduleName}:${entityPath}:remove')") <% } %> <% if(generateLog) { %> @OperationLog <% } %> @DeleteMapping("/batch") public ApiResult removeBatch(@RequestBody List<${primaryKey.propertyType}> ids) { if (${entityPath}Service.removeByIds(ids)) { return success("批量删除成功"); } return error("批量删除失败"); } }