2017-02-22 20 views
0

如果我没有设置paramType =“查询”,密码是正文。如何改变?如何设置要查询的默认参数类型。目前是身体

@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

回答

1

而不是使用像@RequestParam以下设置它在swagger注释应指定查询参数在method的:

@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, "账号或密码错误"); 
} 
+0

谢谢。但我需要ApiImplicitParam.value,有没有办法编写更少的代码,但显示ApiImplicitParam.value和paramType =“查询”? – oldfeel

+0

你应该在参数本身上使用'@ApiModelProperty(value =“xxx”...)'。 – Tom

相关问题