restful风格请求及都是 / 的请求及参数也在请求的/中

 

前台请求的样式:

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

posted @ 2018-09-27 14:27  戈博折刀  阅读(1377)  评论(0编辑  收藏  举报