2025-04-23 11:03:01 +08:00

183 lines
6.0 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.

##导入宏定义
$!{define.vm}
$!{mybatisCodehelper.vm}
##设置表后缀(宏定义)
#set($controllerName = $tool.append($tableInfo.name, "Controller"))
##设置回调
#set($controllerSavePath = $tool.append(${controllerSrcFolder},"/",${controllerPackageName.replace(".","/")}))
$!callback.setSavePath($controllerSavePath)
$!callback.setFileName($tool.append($controllerName, ".java"))
##定义服务名
#set($serviceName = $!tool.append($!tool.firstLowerCase($!tableInfo.name), "Service"))
##定义实体对象名
#set($entityName = $!tool.firstLowerCase($!tableInfo.name))
package ${controllerPackageName};
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.PageDTO;
import {{ cookiecutter.__mvn_package }}.rest.api.ApiController;
import {{ cookiecutter.__mvn_package }}.rest.api.R;
import $!{modelPackageName}.$!{tableInfo.name};
import ${servicePackageName}.$!{tableInfo.name}Service;
import java.io.Serializable;
import java.util.List;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.lang.Nullable;
import org.springframework.web.bind.annotation.*;
##表注释(宏定义)
#tableComment("表控制层.")
###if(${tableInfo.comment})
##@Tag(name = "${tableInfo.comment}")
###end
@Tag(name = "标准接口", description = "由表结构自动生成")
@RestController
@RequestMapping("db/$!tool.firstLowerCase($!tableInfo.name)")
public class $!{tableInfo.name}Controller extends ApiController {
/** 服务对象. */
private final $!{tableInfo.name}Service $!{serviceName};
public $!{tableInfo.name}Controller($!{tableInfo.name}Service $!{serviceName}) {
this.$!{serviceName} = $!{serviceName};
}
/**
* 分页查询所有数据.
*
* @param page 分页对象
* @param $!entityName 查询实体
* @return 分页数据
*/
@Operation(
summary = "${tableInfo.comment} - 分页查询所有数据",
parameters = {
@Parameter(name = "page", description = "分页对象"),
@Parameter(name = "$!entityName", description = "查询实体"),
},
responses = @ApiResponse(description = "分页数据"),
description = "size=-1时查询所有数据orders配合asc排序")
@GetMapping
@SaCheckPermission("db:rest:get")
public R selectAll(@Nullable PageDTO<$!{tableInfo.name}> page, @Nullable $!{tableInfo.name} $!entityName) {
return success(this.$!{serviceName}.page(page, new QueryWrapper<>($!entityName)));
}
/**
* 通过主键查询单条数据.
*
* @param id 主键
* @return 单条数据
*/
@Operation(
summary = "${tableInfo.comment} - 通过主键查询单条数据",
parameters = {
@Parameter(name = "id", description = "主键", schema = @Schema(type = "string")),
},
responses = @ApiResponse(description = "单条数据"))
@GetMapping("{id}")
@SaCheckPermission("db:rest:get")
public R selectOne(@PathVariable Serializable id) {
return success(this.$!{serviceName}.getById(id));
}
/**
* 新增数据.
*
* @param $!entityName 实体对象
* @return 新增结果
*/
@Operation(
summary = "${tableInfo.comment} - 新增数据",
parameters = {
@Parameter(name = "$!entityName", description = "实体对象"),
},
responses = @ApiResponse(description = "新增结果"))
@PostMapping
@SaCheckPermission("db:rest:post")
public R insert(@RequestBody $!tableInfo.name $!entityName) {
return success(this.$!{serviceName}.save($!entityName));
}
/**
* 批量新增数据.
*
* @param $!{entityName}s 实体对象
* @return 新增结果
*/
@Operation(
summary = "${tableInfo.comment} - 批量新增数据",
parameters = {
@Parameter(name = "$!{entityName}s", description = "实体对象"),
},
responses = @ApiResponse(description = "新增结果"))
@PostMapping("s")
@SaCheckPermission("db:rest:post")
public R inserts(@RequestBody List<$!tableInfo.name> $!{entityName}s) {
return success(this.$!{serviceName}.saveBatch($!{entityName}s));
}
/**
* 修改数据.
*
* @param $!entityName 实体对象
* @return 修改结果
*/
@Operation(
summary = "${tableInfo.comment} - 修改数据",
parameters = {@Parameter(name = "$!entityName", description = "实体对象")},
responses = @ApiResponse(description = "修改结果"),
description = "不存在的对象会新增")
@PutMapping
@SaCheckPermission("db:rest:put")
public R update(@RequestBody $!tableInfo.name $!entityName) {
return success(this.$!{serviceName}.saveOrUpdate($!entityName));
}
/**
* 批量修改数据.
*
* @param $!{entityName}s 实体对象
* @return 修改结果
*/
@Operation(
summary = "${tableInfo.comment} - 批量修改数据",
parameters = {@Parameter(name = "$!{entityName}s", description = "实体对象")},
responses = @ApiResponse(description = "修改结果"),
description = "不存在的对象会新增")
@PutMapping("s")
@SaCheckPermission("db:rest:put")
public R updates(@RequestBody List<$!tableInfo.name> $!{entityName}s) {
return success(this.$!{serviceName}.saveOrUpdateBatch($!{entityName}s));
}
/**
* 删除数据.
*
* @param idList 主键结合
* @return 删除结果
*/
@Operation(
summary = "${tableInfo.comment} - 删除数据",
parameters = {
@Parameter(name = "idList", description = "主键结合", schema = @Schema(type = "string"))
},
responses = @ApiResponse(description = "删除结果"),
description = "主键用逗号拼接")
@DeleteMapping
@SaCheckPermission("db:rest:del")
public R delete(@RequestParam("idList") List<Long> idList) {
return success(this.$!{serviceName}.removeByIds(idList));
}
}