方法一:
@ApiOperation("用户注册接口")
@ApiImplicitParams({
@ApiImplicitParam(dataType = "string",name = "username",value = "用户注册账号",required = true),
@ApiImplicitParam(dataType = "string",name = "password",value = "用户注册密码",required = true)
})
@PostMapping("/regist")
public ResultVO regist(@RequestParam("username") String username,
@RequestParam("password") String password){
ResultVO resultVO = userService.userRegist(username,password);
return resultVO;
}
方法二:
@PostMapping("/regist")
public ResultVO regist(String username,
String password){
ResultVO resultVO = userService.userRegist(username,password);
return resultVO;
}
两者区别:
·1· @RequestParam注解可以配置相关的属性,如required属性
·2·
有@RequestParam
时,请求的参数是不可缺省的;
请求路径为user/login?username=xx&password=xx
无@RequestParam
时,请求参数是可以缺省的;
请求路径为user/login
或者user/login?username=xx&password=xx
当然可以在@RequestParam注解中配置required属性,来限定该参数是否可以缺省。