mirror of https://gitee.com/y_project/RuoYi.git
完善swagger2测试案例
parent
72359f3b01
commit
ff10fe098e
|
@ -1,116 +1,144 @@
|
|||
package com.ruoyi.web.controller.tool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.PutMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import com.ruoyi.common.core.controller.BaseController;
|
||||
import com.ruoyi.common.core.domain.AjaxResult;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
|
||||
/**
|
||||
* swagger 测试方法
|
||||
* swagger 用户测试方法
|
||||
*
|
||||
* @author ruoyi
|
||||
*/
|
||||
@Api("用户信息管理")
|
||||
@RestController
|
||||
@RequestMapping("/test/*")
|
||||
@RequestMapping("/test/user")
|
||||
public class TestController extends BaseController
|
||||
{
|
||||
private final static List<Test> testList = new ArrayList<>();
|
||||
private final static Map<Integer, UserEntity> users = new LinkedHashMap<Integer, UserEntity>();
|
||||
{
|
||||
testList.add(new Test("1", "admin", "admin123"));
|
||||
testList.add(new Test("2", "ry", "admin123"));
|
||||
users.put(1, new UserEntity(1, "admin", "admin123", "15888888888"));
|
||||
users.put(2, new UserEntity(2, "ry", "admin123", "15666666666"));
|
||||
}
|
||||
|
||||
@ApiOperation("获取列表")
|
||||
@GetMapping("list")
|
||||
public List<Test> testList()
|
||||
@ApiOperation("获取用户列表")
|
||||
@GetMapping("/list")
|
||||
public AjaxResult userList()
|
||||
{
|
||||
return testList;
|
||||
List<UserEntity> userList = new ArrayList<UserEntity>(users.values());
|
||||
return AjaxResult.success(userList);
|
||||
}
|
||||
|
||||
@ApiOperation("获取用户详细")
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Integer", paramType = "path")
|
||||
@GetMapping("/{userId}")
|
||||
public AjaxResult getUser(@PathVariable Integer userId)
|
||||
{
|
||||
if (!users.isEmpty() && users.containsKey(userId))
|
||||
{
|
||||
return AjaxResult.success(users.get(userId));
|
||||
}
|
||||
else
|
||||
{
|
||||
return error("用户不存在");
|
||||
}
|
||||
}
|
||||
|
||||
@ApiOperation("新增用户")
|
||||
@PostMapping("save")
|
||||
public AjaxResult save(Test test)
|
||||
@ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
|
||||
@PostMapping("/save")
|
||||
public AjaxResult save(UserEntity user)
|
||||
{
|
||||
return testList.add(test) ? success() : error();
|
||||
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
||||
{
|
||||
return error("用户ID不能为空");
|
||||
}
|
||||
return AjaxResult.success(users.put(user.getUserId(), user));
|
||||
}
|
||||
|
||||
@ApiOperation("更新用户")
|
||||
@ApiImplicitParam(name = "Test", value = "单个用户信息", dataType = "Test")
|
||||
@PutMapping("update")
|
||||
public AjaxResult update(Test test)
|
||||
@ApiImplicitParam(name = "userEntity", value = "新增用户信息", dataType = "UserEntity")
|
||||
@PutMapping("/update")
|
||||
public AjaxResult update(UserEntity user)
|
||||
{
|
||||
return testList.remove(test) && testList.add(test) ? success() : error();
|
||||
if (StringUtils.isNull(user) || StringUtils.isNull(user.getUserId()))
|
||||
{
|
||||
return error("用户ID不能为空");
|
||||
}
|
||||
if (users.isEmpty() || !users.containsKey(user.getUserId()))
|
||||
{
|
||||
return error("用户不存在");
|
||||
}
|
||||
users.remove(user.getUserId());
|
||||
return AjaxResult.success(users.put(user.getUserId(), user));
|
||||
}
|
||||
|
||||
@ApiOperation("删除用户")
|
||||
@ApiImplicitParam(name = "Tests", value = "单个用户信息", dataType = "Test")
|
||||
@DeleteMapping("delete")
|
||||
public AjaxResult delete(Test test)
|
||||
@ApiOperation("删除用户信息")
|
||||
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "Integer", paramType = "path")
|
||||
@DeleteMapping("/{userId}")
|
||||
public AjaxResult delete(@PathVariable Integer userId)
|
||||
{
|
||||
return testList.remove(test) ? success() : error();
|
||||
if (!users.isEmpty() && users.containsKey(userId))
|
||||
{
|
||||
users.remove(userId);
|
||||
return success();
|
||||
}
|
||||
else
|
||||
{
|
||||
return error("用户不存在");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class Test
|
||||
@ApiModel("用户实体")
|
||||
class UserEntity
|
||||
{
|
||||
private String userId;
|
||||
@ApiModelProperty("用户ID")
|
||||
private Integer userId;
|
||||
|
||||
@ApiModelProperty("用户名称")
|
||||
private String username;
|
||||
|
||||
@ApiModelProperty("用户密码")
|
||||
private String password;
|
||||
|
||||
public Test()
|
||||
@ApiModelProperty("用户手机")
|
||||
private String mobile;
|
||||
|
||||
public UserEntity()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public Test(String userId, String username, String password)
|
||||
public UserEntity(Integer userId, String username, String password, String mobile)
|
||||
{
|
||||
this.userId = userId;
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.mobile = mobile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (this == o)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (o == null || getClass() != o.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Test test = (Test) o;
|
||||
|
||||
return userId != null ? userId.equals(test.userId) : test.userId == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = userId != null ? userId.hashCode() : 0;
|
||||
result = 31 * result + (username != null ? username.hashCode() : 0);
|
||||
result = 31 * result + (password != null ? password.hashCode() : 0);
|
||||
return result;
|
||||
}
|
||||
|
||||
public String getUserId()
|
||||
public Integer getUserId()
|
||||
{
|
||||
return userId;
|
||||
}
|
||||
|
||||
public void setUserId(String userId)
|
||||
public void setUserId(Integer userId)
|
||||
{
|
||||
this.userId = userId;
|
||||
}
|
||||
|
@ -134,4 +162,14 @@ class Test
|
|||
{
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getMobile()
|
||||
{
|
||||
return mobile;
|
||||
}
|
||||
|
||||
public void setMobile(String mobile)
|
||||
{
|
||||
this.mobile = mobile;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.ruoyi.common.core.domain;
|
|||
import java.util.HashMap;
|
||||
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||
import com.ruoyi.common.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* 操作消息提醒
|
||||
|
@ -85,8 +86,11 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
{
|
||||
super.put(CODE_TAG, type.value);
|
||||
super.put(MSG_TAG, msg);
|
||||
if (StringUtils.isNotNull(data))
|
||||
{
|
||||
super.put(DATA_TAG, data);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
|
@ -98,6 +102,16 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
return AjaxResult.success("操作成功");
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功数据
|
||||
*
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success(Object data)
|
||||
{
|
||||
return AjaxResult.success("操作成功", data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 返回成功消息
|
||||
*
|
||||
|
@ -218,11 +232,9 @@ public class AjaxResult extends HashMap<String, Object>
|
|||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||
.append("code", getCode())
|
||||
.append("msg", getMsg())
|
||||
.append("data", getData())
|
||||
.toString();
|
||||
public String toString()
|
||||
{
|
||||
return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE).append("code", getCode())
|
||||
.append("msg", getMsg()).append("data", getData()).toString();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue