This article mainly studies the difference between @PathParam and @QueryParam, as follows.
Today, I debugged an upload function. The client sends data with a mobile phone and attaches a parameter to the URL. The background uses @PathParam to receive it, but an error is reported and this parameter cannot be obtained.
url: http://192.168.1.3/web1_service/convert/vict_hj1000?unit=160106
@Path("/vict_hj1000") @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Response createVictHJ1000Detect(@FormDataParam("name0") InputStream uploadedInputStream, @PathParam("unit") Long unit) throws JSONException { In other words, if this unit parameter cannot be obtained, what's going on?
I checked it online and found the reason. The parameters in the url are written incorrectly, which makes the background @PathParam unable to be obtained. The following lists the differences between @PathParam and @QueryParam:
1. @PathParam , add parameter values directly after the slash in the url, for example: www.a.com/student/001;
2. @QueryParam, add parameters in the form of [key-value pair] to the url, for example: www.a.com/student?id=001;
In my application, url uses parameters in the form of key-value pairs, while the background uses @PathParam, which does not match, so it cannot be obtained.
The solution is to modify the URL, cancel the key-value pair, directly add the parameter value after the slash, and change it to:
http://192.168.1.3/web1_service/convert/vict_hj1000/160106
And modify the @Path annotation in the background and change it to:
@Path("/vict_hj1000/{unit}")Problem solved!
The above is all the content of this article about the difference between @PathParam and @QueryParam. I hope it will be helpful to everyone. Interested friends can continue to refer to other related topics on this site. If there are any shortcomings, please leave a message to point it out. Thank you friends for your support for this site!