若依后台管理系统test接口编写错误
缘起
@ApiOperation("获取用户表列")
@GetMapping("{userlist}")
public AjaxResult get1234567() {
List<UserEntity> userList2 = new ArrayList<UserEntity>(users.values());
return AjaxResult.success(userList2);}
@ApiOperation("获取用户详细信息")
@ApiImplicitParam(name = "useId", value = "用户ID", required = true, dataType = "int", 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("获取用户详细信息")
@ApiImplicitParam(name = "userId", value = "用户ID", required = true, dataType = "int", 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("获取用户表列")
@GetMapping("/userinfo/userlist")
public AjaxResult get1234567()
{
List<UserEntity> userList2 = new ArrayList<UserEntity>(users.values());
return AjaxResult.success(userList2);
}
接下来重新启动若依
再次来到接口的地方
发现问题解决了,可以根据用户Id查询到用户的详细信息了。
总结一下原因:
一开始接口写的查询列表在上面,先获取了用户输入的数字,但实际上查询列表的接口是不需要用户输入参数的,所以我们后面将{}修改为路径,调整一下接口顺序就可以解决,因为程序自上而下执行,所以建议按理想顺序填写,,不要误传参数