UserController.java 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. * 用户管理
  20. *
  21. * @author makejava
  22. * create on 2023-03-17 09:06:58
  23. */
  24. @RestController
  25. @RequestMapping("user")
  26. @RequiredArgsConstructor(onConstructor_ = {@Autowired})
  27. public class UserController {
  28. /**
  29. * 服务对象
  30. */
  31. private final UserService userService;
  32. /**
  33. * 查询所有数据
  34. *
  35. * @return 所有数据
  36. */
  37. @GetMapping("/queryAll")
  38. public Result<List<User>> queryAll() {
  39. return Result.success(userService.queryAll());
  40. }
  41. /**
  42. * 分页查询数据
  43. *
  44. * @return 所有数据
  45. */
  46. @GetMapping("/queryPage")
  47. public Result<List<User>> queryPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, User user) {
  48. PageQuery<User> pageQuery = new PageQuery<User>();
  49. pageQuery.setPageSize(pageSize);
  50. pageQuery.setPageNumber(pageNum);
  51. pageQuery.setParas(user);
  52. return userService.queryByPage(pageQuery);
  53. }
  54. /**
  55. * 通过主键查询单条数据
  56. *
  57. * @param id 主键
  58. * @return 单条数据
  59. */
  60. @GetMapping("/queryOne")
  61. public Result<User> queryOne(@RequestParam("id") Integer id) {
  62. return Result.success(userService.queryById(id));
  63. }
  64. /**
  65. * 通过主键查询单条数据
  66. *
  67. * @return 单条数据
  68. */
  69. @GetMapping("/getUserInfo")
  70. public Result<User> getUserInfo() {
  71. return Result.success();
  72. }
  73. /**
  74. * 新增数据
  75. *
  76. * @param user 实体对象
  77. * @return 新增结果
  78. */
  79. @PostMapping("/create")
  80. public Result<?> create(@RequestBody User user) {
  81. userService.insert(user);
  82. return Result.success(user);
  83. }
  84. /**
  85. * 修改数据
  86. *
  87. * @param user 实体对象
  88. * @return 修改结果
  89. */
  90. @PostMapping("/update")
  91. public Result<?> update(@RequestBody User user) {
  92. return userService.updateById(user) ? Result.success() : Result.failure();
  93. }
  94. /**
  95. * 删除数据
  96. *
  97. * @param id 主键
  98. * @return 删除结果
  99. */
  100. @PostMapping("/delete")
  101. public Result<Boolean> delete(@RequestParam("id") Integer id) {
  102. return Result.success(this.userService.deleteById(id));
  103. }
  104. }