@PathParam、PathVariable、@RequestParam的区别

@PathParam:(//)

例如:Postman请求格式 为  http://localhost:8080/ct/customer/list/1/10

 @GET
 @Path("/list/{page}/{pageSize}")
 public Pageable<Customer> listPage(@PathParam("page") int page,@PathParam("pageSize") int pageSize) {
   return this.getService().getAll(this.getQueryFilter(),page,pageSize);
 }

@PathVariable(??)

例如:Postman请求格式  http://localhost:8080/ct/customer/hello/101?param1=10&param2=20

 @RequestMapping("/hello/{id}")
 public String getDetails(@PathVariable(value="id") String id,
 @RequestParam(value="param1", required=true) String param1,
 @RequestParam(value="param2", required=false) String param2){
.......
}

@RequestParam(??)

例如:Postman请求格式 http://localhost:8080/springmvc/hello/101?param1=10&param2=20

 public String getDetails(
     @RequestParam(value="param1", required=true) String param1,
         @RequestParam(value="param2", required=false) String param2){
 ...
 }

@RequestParam  @PathVariable 注解是用于从request中接收请求的,两个都可以接收参数,关键点不同的是@RequestParam 是从request里面拿取值,而 @PathVariable 是从一个URI模板里面来填充。。

@PathParam这个注解是和springpathVariable是一样的,也是基于模板的,但是这个是jboss包下面的一个实现,上面的是spring的一个实现,都要导包

猜你喜欢

转载自blog.csdn.net/RuiKe1400360107/article/details/82112800