TestController.java 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package com.ruoyi.project.tool.swagger;
  2. import java.util.ArrayList;
  3. import java.util.List;
  4. import org.springframework.web.bind.annotation.DeleteMapping;
  5. import org.springframework.web.bind.annotation.GetMapping;
  6. import org.springframework.web.bind.annotation.PostMapping;
  7. import org.springframework.web.bind.annotation.PutMapping;
  8. import org.springframework.web.bind.annotation.RequestMapping;
  9. import org.springframework.web.bind.annotation.RestController;
  10. import com.ruoyi.framework.web.controller.BaseController;
  11. import com.ruoyi.framework.web.domain.AjaxResult;
  12. import io.swagger.annotations.Api;
  13. import io.swagger.annotations.ApiImplicitParam;
  14. import io.swagger.annotations.ApiOperation;
  15. /**
  16. * swagger 测试方法
  17. *
  18. * @author ruoyi
  19. */
  20. @Api("用户信息管理")
  21. @RestController
  22. @RequestMapping("/test/*")
  23. public class TestController extends BaseController
  24. {
  25. private final static List<Test> testList = new ArrayList<>();
  26. {
  27. testList.add(new Test("1", "admin", "admin123"));
  28. testList.add(new Test("2", "ry", "admin123"));
  29. }
  30. @ApiOperation("获取列表")
  31. @GetMapping("list")
  32. public List<Test> testList()
  33. {
  34. return testList;
  35. }
  36. @ApiOperation("新增用户")
  37. @PostMapping("save")
  38. public AjaxResult save(Test test)
  39. {
  40. return testList.add(test) ? success() : error();
  41. }
  42. @ApiOperation("更新用户")
  43. @ApiImplicitParam(name = "Test", value = "单个用户信息", dataType = "Test")
  44. @PutMapping("update")
  45. public AjaxResult update(Test test)
  46. {
  47. return testList.remove(test) && testList.add(test) ? success() : error();
  48. }
  49. @ApiOperation("删除用户")
  50. @ApiImplicitParam(name = "Tests", value = "单个用户信息", dataType = "Test")
  51. @DeleteMapping("delete")
  52. public AjaxResult delete(Test test)
  53. {
  54. return testList.remove(test) ? success() : error();
  55. }
  56. }
  57. class Test
  58. {
  59. private String userId;
  60. private String username;
  61. private String password;
  62. public Test()
  63. {
  64. }
  65. public Test(String userId, String username, String password)
  66. {
  67. this.userId = userId;
  68. this.username = username;
  69. this.password = password;
  70. }
  71. @Override
  72. public boolean equals(Object o)
  73. {
  74. if (this == o)
  75. {
  76. return true;
  77. }
  78. if (o == null || getClass() != o.getClass())
  79. {
  80. return false;
  81. }
  82. Test test = (Test) o;
  83. return userId != null ? userId.equals(test.userId) : test.userId == null;
  84. }
  85. @Override
  86. public int hashCode()
  87. {
  88. int result = userId != null ? userId.hashCode() : 0;
  89. result = 31 * result + (username != null ? username.hashCode() : 0);
  90. result = 31 * result + (password != null ? password.hashCode() : 0);
  91. return result;
  92. }
  93. public String getUserId()
  94. {
  95. return userId;
  96. }
  97. public void setUserId(String userId)
  98. {
  99. this.userId = userId;
  100. }
  101. public String getUsername()
  102. {
  103. return username;
  104. }
  105. public void setUsername(String username)
  106. {
  107. this.username = username;
  108. }
  109. public String getPassword()
  110. {
  111. return password;
  112. }
  113. public void setPassword(String password)
  114. {
  115. this.password = password;
  116. }
  117. }