TestController.java 3.2 KB

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