0

If I do not set paramType = "query", password is body. How to change?

@ApiOperation("登录")
@ApiImplicitParams({
        @ApiImplicitParam(name = "account", value = "用户名或手机号码", paramType = "query"),
        @ApiImplicitParam(name = "password", value = "密码")
})
@RequestMapping
public JR login(String account, String password) {
    if (StringUtils.isEmpty(account) || StringUtils.isEmpty(password)) {
        return JR.fail(2, "请填写完整信息");
    }
    User user = userRepository.findByAccountOrPhone(account, account);
    if (user != null && StringUtils.md5(password).equals(user.getPassword())) {
        ApiUtils.loginInfo(user, userRepository, true);
        return JR.success(user);
    }
    return JR.fail(1, "账号或密码错误");
}

enter image description here

oldfeel
  • 420
  • 3
  • 12

1 Answers1

1

Instead of setting it in the swagger annotation you should specify query params in your method using @RequestParam like the following:

@ApiOperation("登录")
@RequestMapping
public JR login(@RequestParam("account")  String account, @RequestParam("password") String password) {
    if (StringUtils.isEmpty(account) || StringUtils.isEmpty(password)) {
        return JR.fail(2, "请填写完整信息");
    }
    User user = userRepository.findByAccountOrPhone(account, account);
    if (user != null && StringUtils.md5(password).equals(user.getPassword())) {
        ApiUtils.loginInfo(user, userRepository, true);
        return JR.success(user);
    }
    return JR.fail(1, "账号或密码错误");
}
Tom
  • 3,711
  • 2
  • 25
  • 31
  • Thank you. But I need ApiImplicitParam.value, is there a way to write less code but show ApiImplicitParam.value and paramType="query"? – oldfeel Feb 22 '17 at 22:10
  • you should use `@ApiModelProperty(value = "xxx"...)` on the parameter itself. – Tom Feb 22 '17 at 22:24