@PathVariable @RequestParam使用

@RequestParam,接收get或者post方式的前端參數。如果前端傳遞的參數和後端你接受的參數的字段名稱是一致的可以省略不寫,也可以直接寫@RequestParam String id,如下面的接收前端傳過來的id。這種情況參數不會拼接在URL上面。

    @GetMapping("xxx/xxx")
    public RequestResult get(
            @ApiParam(name = "id", value = "主鍵", required = true)  String id){}

@PathVariable,主要是用get方式接參,參數拼接在url後面。

    @GetMapping("xxx/xxx/{id}")
    public RequestResult get(
            @ApiParam(name = "id", value = "主鍵", required = true) @PathVariable("id") String id) {}

@ApiParam只是用於生成swagger的文檔註釋參數而已。

 

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