@PathVariable和@RequestParam的不同用法

@RequestParam註解是獲取靜態URL傳入的參數

@PathVariable是獲取請求路徑中的變量作爲參數

 	@GetMapping("update")
    public void updateCategory(@RequestParam("id") Long id, @RequestParam("name") String name){

        this.categoryService.updateCategory(id,name);

    }

    @GetMapping("bid/{bid}")
    public ResponseEntity<List<Category>> queryByBrandId(@PathVariable("bid") Long bid){

        List<Category> lists=this.categoryService.queryByBrandId(bid);

        if (CollectionUtils.isEmpty(lists)){

            return ResponseEntity.notFound().build();
        }
        return ResponseEntity.ok(lists);

    }
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章