What is the difference between @PathParam and @PathVariable

后端 未结 7 1602
天涯浪人
天涯浪人 2020-12-23 19:21

To my knowledge both serves the same purpose. Except the fact that @PathVariable is from Spring MVC and @PathParam is from JAX-RS. Any insights on

7条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-23 19:50

    QueryParam:

    To assign URI parameter values to method arguments. In Spring, it is @RequestParam.

    Eg.,

    http://localhost:8080/books?isbn=1234
    
    @GetMapping("/books/")
        public Book getBookDetails(@RequestParam("isbn") String isbn) {
    

    PathParam:

    To assign URI placeholder values to method arguments. In Spring, it is @PathVariable.

    Eg.,

    http://localhost:8080/books/1234
    
    @GetMapping("/books/{isbn}")
        public Book getBook(@PathVariable("isbn") String isbn) {
    

提交回复
热议问题