controller.vm 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package ${basePackage}.${table.moduleName}.controller.${table.businessName};
  2. import org.springframework.web.bind.annotation.*;
  3. import javax.annotation.Resource;
  4. import org.springframework.validation.annotation.Validated;
  5. import io.swagger.annotations.*;
  6. import javax.validation.constraints.*;
  7. import javax.validation.*;
  8. import java.util.*;
  9. import ${PageResultClassName};
  10. import ${CommonResultClassName};
  11. import static ${CommonResultClassName}.success;
  12. import ${basePackage}.${table.moduleName}.controller.${table.businessName}.vo.*;
  13. import ${basePackage}.${table.moduleName}.dal.dataobject.${table.businessName}.${table.className}DO;
  14. import ${basePackage}.${table.moduleName}.convert.${table.businessName}.${table.className}Convert;
  15. import ${basePackage}.${table.moduleName}.service.${table.businessName}.${table.className}Service;
  16. @Api(tags = "${table.classComment}")
  17. @RestController
  18. ##二级的 businessName 暂时不算在 HTTP 路径上,可以根据需要写
  19. @RequestMapping("/${table.moduleName}/${simpleClassName_strikeCase}")
  20. @Validated
  21. public class ${table.className}Controller {
  22. @Resource
  23. private ${table.className}Service ${classNameVar}Service;
  24. @ApiOperation("创建${table.classComment}")
  25. @PostMapping("/create")
  26. public CommonResult<${primaryColumn.javaType}> create${simpleClassName}(@Valid ${table.className}CreateReqVO createReqVO) {
  27. return success(${classNameVar}Service.create${simpleClassName}(createReqVO));
  28. }
  29. @ApiOperation("更新${table.classComment}")
  30. @PutMapping("/update")
  31. public CommonResult<Boolean> update${simpleClassName}(@Valid ${table.className}UpdateReqVO updateReqVO) {
  32. ${classNameVar}Service.update${simpleClassName}(updateReqVO);
  33. return success(true);
  34. }
  35. @ApiOperation("删除${table.classComment}")
  36. @DeleteMapping("/delete")
  37. @ApiImplicitParam(name = "id", value = "编号", required = true)
  38. public CommonResult<Boolean> delete${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
  39. ${classNameVar}Service.delete${simpleClassName}(id);
  40. return success(true);
  41. }
  42. @GetMapping("/get")
  43. @ApiOperation("获得${table.classComment}")
  44. @ApiImplicitParam(name = "id", value = "编号", required = true, dataTypeClass = ${primaryColumn.javaType}.class)
  45. public CommonResult<${table.className}RespVO> get${simpleClassName}(@RequestParam("id") ${primaryColumn.javaType} id) {
  46. ${table.className}DO ${classNameVar} = ${classNameVar}Service.get${simpleClassName}(id);
  47. return success(${table.className}Convert.INSTANCE.convert(${classNameVar}));
  48. }
  49. @GetMapping("/list")
  50. @ApiOperation("获得${table.classComment}列表")
  51. @ApiImplicitParam(name = "ids", value = "编号列表", required = true, dataTypeClass = List.class)
  52. public CommonResult<List<${table.className}RespVO>> get${simpleClassName}List(@RequestParam("ids") Collection<${primaryColumn.javaType}> ids) {
  53. List<${table.className}DO> list = ${classNameVar}Service.get${simpleClassName}List(ids);
  54. return success(${table.className}Convert.INSTANCE.convertList(list));
  55. }
  56. @ApiOperation("获得${table.classComment}分页")
  57. @GetMapping("/page")
  58. public CommonResult<PageResult<${table.className}RespVO>> get${simpleClassName}Page(@Valid ${table.className}PageReqVO pageVO) {
  59. PageResult<${table.className}DO> pageResult = ${classNameVar}Service.get${simpleClassName}Page(pageVO);
  60. return success(${table.className}Convert.INSTANCE.convertPage(pageResult));
  61. }
  62. }