Controller.java.vm 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. package ${package}.${moduleName}.controller;
  2. import java.util.Arrays;
  3. import java.util.Map;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.web.bind.annotation.*;
  6. import com.baomidou.mybatisplus.plugins.Page;
  7. import com.pig4cloud.pigx.common.core.util.Query;
  8. import ${package}.${moduleName}.entity.${className};
  9. import ${package}.${moduleName}.service.${className}Service;
  10. import com.pig4cloud.pigx.common.core.util.R;
  11. import java.util.Map;
  12. /**
  13. * ${comments}
  14. *
  15. * @author ${author}
  16. * @date ${datetime}
  17. */
  18. @RestController
  19. @RequestMapping("/${pathName}")
  20. public class ${className}Controller {
  21. @Autowired
  22. private ${className}Service ${classname}Service;
  23. /**
  24. * 列表
  25. * @param params
  26. * @return
  27. */
  28. @GetMapping("/page")
  29. public Page page(@RequestParam Map<String, Object> params) {
  30. return ${classname}Service.selectPage(new Query<>(params), new EntityWrapper<>());
  31. }
  32. /**
  33. * 信息
  34. * @param ${pk.lowerAttrName}
  35. * @return R
  36. */
  37. @GetMapping("/{${pk.lowerAttrName}}")
  38. public R info(@PathVariable("${pk.lowerAttrName}") ${pk.attrType} ${pk.lowerAttrName}){
  39. ${className} ${classname} = ${classname}Service.selectById(${pk.lowerAttrName});
  40. return new R<>(${classname});
  41. }
  42. /**
  43. * 保存
  44. * @param ${classname}
  45. * @return R
  46. */
  47. @PostMapping
  48. public R save(@RequestBody ${className} ${classname}){
  49. ${classname}Service.insert(${classname});
  50. return new R<>(Boolean.TRUE);
  51. }
  52. /**
  53. * 修改
  54. * @param ${classname}
  55. * @return R
  56. */
  57. @PutMapping
  58. public R update(@RequestBody ${className} ${classname}){
  59. ${classname}Service.updateById(${classname});
  60. return new R<>(Boolean.TRUE);
  61. }
  62. /**
  63. * 删除
  64. * @param ${pk.lowerAttrName}s
  65. * @return R
  66. */
  67. @DeleteMapping
  68. public R delete(@RequestBody ${pk.attrType}[] ${pk.lowerAttrName}s){
  69. ${classname}Service.deleteBatchIds(Arrays.asList(${pk.lowerAttrName}s));
  70. return new R<>(Boolean.TRUE);
  71. }
  72. }