前台请求的样式:

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

相关文章: