1.例子URL
http://127.0.0.1/item/xxx
{xxx}
叫做占位符,请求的URL可以是“item /1”
或“item/2”
2.从URL上获取参数
如果@RequestMapping
中表示为"item/{id}"
,id
和形参名称一致,@PathVariable
不用指定名称。如果不一致,例如"item/{ItemId}"
则需要指定名称@PathVariable("itemId")
@RequestMapping("item/{id}") //使用注解@RequestMapping("item/{id}")声明请求的url
@ResponseBody
public Item queryItemById(@PathVariable() Integer id) { //使用(@PathVariable() Integer id)获取url上的数据
Item item = this.itemService.queryItemById(id);
return item;
}
本文由 创作,采用 知识共享署名4.0 国际许可协议进行许可。本站文章除注明转载/出处外,均为本站原创或翻译,转载前请务必署名。最后编辑时间为: 2020/05/16 03:45