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 this?
相关问题
- org.apache.commons.fileupload.disk.DiskFileItem is
- @DateTimeFormat in Spring produces off-by-one day
- Java-Reflection - find the Arguments and the annot
- Json string from LocalDateTime(java 8) in Spring M
-
type not resolved
相关文章
- spring-mvc a标签带参怎样向controller发送请求。路径格式?
- Java spring framework - how to set content type?
- Java/Spring MVC: provide request context to child
- Spring 5 Web Reactive - Hot Publishing - How to us
- Cannot use org.jvnet.jax-ws-commons.jaxws-maven-pl
- Spring MVC project not able to publish and run… Me
- Intercept @RequestHeader exception for missing hea
- “400 Bad Request” response for AJAX request
PathParam:
To assign URI parameter values to method arguments. In Spring, it is
@RequestParam
.Eg.,
PathVariable:
To assign URI placeholder values to method arguments.
Eg.,
@PathParam is a parameter annotation which allows you to map variable URI path fragments into your method call.
for more details : JBoss DOCS
In Spring MVC you can use the @PathVariable annotation on a method argument to bind it to the value of a URI template variable for more details : SPRING DOCS
@PathVariable
@PathVariable it is the annotation, that is used in the URI for the incoming request. Let’s look below
http://localhost:8080/restcalls/101?id=10&name=xyz
@RequestParam
@RequestParam annotation used for accessing the query parameter values from the request.
Note
whatever we are requesting with rest call i.e, @PathVariable
whatever we are accessing for writing queries i.e, @RequestParam
@PathVariable and @PathParam both are used for accessing parameters from URI Template
Differences:
@PathParam
is a parameter annotation which allows you to map variable URI path fragments into your method call.@PathVariable
is to obtain some placeholder from the URI (Spring call it an URI Template)