qq_37523925 2017-08-10 03:09 采纳率: 0%
浏览 1796

@PathVariable和@RequestParam的区别

@RequestMapping(value = "/{id}",method = RequestMethod.PUT)
public String updateAccount(@PathVariable("id") int id, @RequestParam(value = "mame",required = true)String name,
@RequestParam(value = "money",required = true)double money){
Account account=new Account();
account.setMoney(money);
account.setName(name);
account.setId(id);
int t=accountService.update(account);
if (t==1){
return account.toString();
}else {
return "fail";
}
}

    我用测试工具通不过  可能是@PathVariable和@RequestParam的问题
    {

"timestamp": 1502334349157,
"status": 400,
"error": "Bad Request",
"exception": "org.springframework.web.bind.MissingServletRequestParameterException",
"message": "Required String parameter 'mame' is not present",
"path": "/account/3"
}
这个是测试工具的反馈

  • 写回答

5条回答 默认 最新

  • 枫叶梨花 2017-08-10 03:12
    关注

    主要是url的不同
    @RequestParam时,url:http://localhost:port/path?参数名=参数值
    @PathVariable时, url:http://localhost:port/path/参数值

    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料