Controller.java.vm 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /*
  2. * Copyright (c) 2018-2025, lengleng All rights reserved.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions are met:
  6. *
  7. * Redistributions of source code must retain the above copyright notice,
  8. * this list of conditions and the following disclaimer.
  9. * Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. * Neither the name of the pig4cloud.com developer nor the names of its
  13. * contributors may be used to endorse or promote products derived from
  14. * this software without specific prior written permission.
  15. * Author: lengleng (wangiegie@gmail.com)
  16. */
  17. package ${package}.${moduleName}.controller;
  18. import com.baomidou.mybatisplus.core.toolkit.Wrappers;
  19. import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
  20. import com.pig4cloud.pigx.common.core.util.R;
  21. import com.pig4cloud.pigx.common.log.annotation.SysLog;
  22. import ${package}.${moduleName}.entity.${className};
  23. import ${package}.${moduleName}.service.${className}Service;
  24. import lombok.AllArgsConstructor;
  25. import org.springframework.web.bind.annotation.*;
  26. /**
  27. * ${comments}
  28. *
  29. * @author ${author}
  30. * @date ${datetime}
  31. */
  32. @RestController
  33. @AllArgsConstructor
  34. @RequestMapping("/${pathName}")
  35. public class ${className}Controller {
  36. private final ${className}Service ${classname}Service;
  37. /**
  38. * 分页查询
  39. * @param page 分页对象
  40. * @param ${classname} ${comments}
  41. * @return
  42. */
  43. @GetMapping("/page")
  44. public R get${className}Page(Page page, ${className} ${classname}) {
  45. return new R<>(${classname}Service.page(page,Wrappers.query(${classname})));
  46. }
  47. /**
  48. * 通过id查询${comments}
  49. * @param ${pk.lowerAttrName} id
  50. * @return R
  51. */
  52. @GetMapping("/{${pk.lowerAttrName}}")
  53. public R getById(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
  54. return new R<>(${classname}Service.getById(${pk.lowerAttrName}));
  55. }
  56. /**
  57. * 新增${comments}
  58. * @param ${classname} ${comments}
  59. * @return R
  60. */
  61. @SysLog("新增${comments}")
  62. @PostMapping
  63. public R save(@RequestBody ${className} ${classname}){
  64. return new R<>(${classname}Service.save(${classname}));
  65. }
  66. /**
  67. * 修改${comments}
  68. * @param ${classname} ${comments}
  69. * @return R
  70. */
  71. @SysLog("修改${comments}")
  72. @PutMapping
  73. public R updateById(@RequestBody ${className} ${classname}){
  74. return new R<>(${classname}Service.updateById(${classname}));
  75. }
  76. /**
  77. * 通过id删除${comments}
  78. * @param ${pk.lowerAttrName} id
  79. * @return R
  80. */
  81. @SysLog("删除${comments}")
  82. @DeleteMapping("/{${pk.lowerAttrName}}")
  83. public R removeById(@PathVariable ${pk.attrType} ${pk.lowerAttrName}){
  84. return new R<>(${classname}Service.removeById(${pk.lowerAttrName}));
  85. }
  86. }