1. ##定义初始变量
    2. #set($tableName = $tool.append($tableInfo.name, "Controller"))
    3. ##设置回调
    4. $!callback.setFileName($tool.append($tableName, ".java"))
    5. $!callback.setSavePath($tool.append($tableInfo.savePath, "/controller"))
    6. ##拿到主键
    7. #if(!$tableInfo.pkColumn.isEmpty())
    8. #set($pk = $tableInfo.pkColumn.get(0))
    9. #end
    10. #if($tableInfo.savePackageName)package $!{tableInfo.savePackageName}.#{end}controller;
    11. import $!{tableInfo.savePackageName}.entity.$!{tableInfo.name};
    12. import $!{tableInfo.savePackageName}.service.$!{tableInfo.name}Service;
    13. import org.springframework.data.domain.Page;
    14. import org.springframework.data.domain.PageRequest;
    15. import org.springframework.http.ResponseEntity;
    16. import org.springframework.web.bind.annotation.*;
    17. import javax.annotation.Resource;
    18. /**
    19. * $!{tableInfo.comment}($!{tableInfo.name})表控制层
    20. *
    21. * @author $!author
    22. * @since $!time.currTime()
    23. */
    24. @RestController
    25. @RequestMapping("$!tool.firstLowerCase($tableInfo.name)")
    26. public class $!{tableName} {
    27. /**
    28. * 服务对象
    29. */
    30. @Resource
    31. private $!{tableInfo.name}Service $!tool.firstLowerCase($tableInfo.name)Service;
    32. /**
    33. * 通过主键查询单条数据
    34. *
    35. * @param id 主键
    36. * @return 单条数据
    37. */
    38. @GetMapping("{id}")
    39. public ResponseEntity<$!{tableInfo.name}> queryById(@PathVariable("id") $!pk.shortType id) {
    40. return ResponseEntity.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.queryById(id));
    41. }
    42. /**
    43. * 新增数据
    44. *
    45. * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
    46. * @return 新增结果
    47. */
    48. @PostMapping
    49. public ResponseEntity<$!{tableInfo.name}> add($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
    50. return ResponseEntity.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.insert($!{tool.firstLowerCase($tableInfo.name)}));
    51. }
    52. /**
    53. * 编辑数据
    54. *
    55. * @param $!{tool.firstLowerCase($tableInfo.name)} 实体
    56. * @return 编辑结果
    57. */
    58. @PutMapping
    59. public ResponseEntity<$!{tableInfo.name}> edit($!{tableInfo.name} $!{tool.firstLowerCase($tableInfo.name)}) {
    60. return ResponseEntity.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.update($!{tool.firstLowerCase($tableInfo.name)}));
    61. }
    62. /**
    63. * 删除数据
    64. *
    65. * @param id 主键
    66. * @return 删除是否成功
    67. */
    68. @DeleteMapping
    69. public ResponseEntity<Boolean> deleteById($!pk.shortType id) {
    70. return ResponseEntity.ok(this.$!{tool.firstLowerCase($tableInfo.name)}Service.deleteById(id));
    71. }
    72. }