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/参数值

    评论

报告相同问题?

悬赏问题

  • ¥20 fluent无法启动
  • ¥15 孟德尔随机化r语言运行问题
  • ¥15 pyinstaller编译的时候出现No module named 'imp'
  • ¥15 nirs_kit中打码怎么看(打码文件是csv格式)
  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。