UserController.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. package com.benyun.controller;
  2. import com.benyun.boot.core.vo.Result;
  3. import lombok.RequiredArgsConstructor;
  4. import com.benyun.entity.User;
  5. import com.benyun.service.UserService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.web.bind.annotation.DeleteMapping;
  8. import org.springframework.web.bind.annotation.GetMapping;
  9. import org.springframework.web.bind.annotation.PathVariable;
  10. import org.springframework.web.bind.annotation.PostMapping;
  11. import org.springframework.web.bind.annotation.PutMapping;
  12. import org.springframework.web.bind.annotation.RequestBody;
  13. import org.springframework.web.bind.annotation.RequestMapping;
  14. import org.springframework.web.bind.annotation.RequestParam;
  15. import org.springframework.web.bind.annotation.RestController;
  16. import org.beetl.sql.core.engine.PageQuery;
  17. import java.util.List;
  18. /**
  19. * @author makejava
  20. * create on 2023-03-17 09:06:58
  21. */
  22. @RestController
  23. @RequestMapping("user")
  24. @RequiredArgsConstructor(onConstructor_ = {@Autowired})
  25. public class UserController {
  26. /**
  27. * 服务对象
  28. */
  29. private final UserService userService;
  30. /**
  31. * 查询所有数据
  32. *
  33. * @return 所有数据
  34. */
  35. @GetMapping("/queryAll")
  36. public Result<List<User>> queryAll() {
  37. return Result.success(userService.queryAll());
  38. }
  39. /**
  40. * 分页查询数据
  41. *
  42. * @return 所有数据
  43. */
  44. @GetMapping("/queryPage")
  45. public Result<List<User>> queryPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, User user) {
  46. PageQuery<User> pageQuery = new PageQuery<User>();
  47. pageQuery.setPageSize(pageSize);
  48. pageQuery.setPageNumber(pageNum);
  49. pageQuery.setParas(user);
  50. return userService.queryByPage(pageQuery);
  51. }
  52. /**
  53. * 通过主键查询单条数据
  54. *
  55. * @param id 主键
  56. * @return 单条数据
  57. */
  58. @GetMapping("/queryOne")
  59. public Result<User> queryOne(@RequestParam("id") Integer id) {
  60. return Result.success(userService.queryById(id));
  61. }
  62. /**
  63. * 通过主键查询单条数据
  64. *
  65. * @return 单条数据
  66. */
  67. @GetMapping("/getUserInfo")
  68. public Result<User> getUserInfo() {
  69. return Result.success();
  70. }
  71. /**
  72. * 新增数据
  73. *
  74. * @param user 实体对象
  75. * @return 新增结果
  76. */
  77. @PostMapping("/create")
  78. public Result<?> create(@RequestBody User user) {
  79. userService.insert(user);
  80. return Result.success(user);
  81. }
  82. /**
  83. * 修改数据
  84. *
  85. * @param user 实体对象
  86. * @return 修改结果
  87. */
  88. @PostMapping("/update")
  89. public Result<?> update(@RequestBody User user) {
  90. return userService.updateById(user) ? Result.success() : Result.failure();
  91. }
  92. /**
  93. * 删除数据
  94. *
  95. * @param id 主键
  96. * @return 删除结果
  97. */
  98. @PostMapping("/delete")
  99. public Result<Boolean> delete(@RequestParam("id") Integer id) {
  100. return Result.success(this.userService.deleteById(id));
  101. }
  102. }