一、form格式请求
以表单形式提交,默认 @RequestParam
@ApiOperation(value = "测试接口",httpMethod = "GET",response = Result.class,notes = "测试接口")
@RequestMapping(value = "/GetUserInfo",method = RequestMethod.GET)
public Result GetUserInfo(GetUserInfoRequest param){
User userInfo = userService.getUserInfoById(param.getUserId());
return Result.success(userInfo);
}
也可以这样写
@ApiOperation(value = "测试接口",httpMethod = "GET",response = Result.class,notes = "测试接口")
@RequestMapping(value = "/GetUserInfo",method = RequestMethod.GET)
public Result GetUserInfo(@RequestParam GetUserInfoRequest param){
User userInfo = userService.getUserInfoById(param.getUserId());
return Result.success(userInfo);
}
请求方式
application/x-www-form-urlencoded
二、requestbody json格式
以json格式提交,用RequestBody声明
@RequestMapping(value = "/InsertUserInfo", method = RequestMethod.POST)
@ApiOperation(value = "提交用户信息", notes="返回成功失败")
public Result InsertUserInfo(@RequestBody PostUserInfoRequest userInfo) {
System.out.println("进来了 InsertUserInfo");
try
{
//对象转换
User info1 = new User();
BeanUtils.copyProperties(userInfo, info1);
User info = new User();
info.setUserId(userInfo.getUserId());
info.setUserAccount(userInfo.getUserAccount());
info.setUserPass(userInfo.getUserPass());
info.setUserPhone(userInfo.getUserPhone());
info.setUserPhoto(userInfo.getUserPhoto());
info.setUserState(userInfo.getUserState());
int code = userService.InsertInfo(info);
if(code == 1) {
User uInfo = userService.getUserInfoById(info.getUserId());
return Result.success(uInfo);
}
}
catch (Exception e)
{
logger.error("写入数据库失败", e);
}
return Result.failure(-1,"插入错误");
}
请求方式
application/json