前台請求的樣式:
http://localhost:8080/item/88909
其中參數就是最后的 商品id號 88909
后台Controller中取出參數的方法:
@Controller public class ItemController { @Autowired private ItemService itemService; @RequestMapping("/item/{itemId}") @ResponseBody public TbItem getItemById(@PathVariable Long itemId) { TbItem tbItem = itemService.getItemById(itemId); return tbItem; } }
注意:這種寫法時,參數中一定要用注解 @PathVariable