如何从以下uri字符串中获取路径参数和矩阵参数? Uri是/ flights / flightid; numberofseats = 2 / date

时间:2022-04-05 15:54:14

Am trying to separate the path param and matrix param from the following uri string in jersey.

我试图将路径参数和矩阵参数与球衣中的以下uri字符串分开。

/flights/flightid;numberofseats=2/date.

Things I wanna separate following parameters using jersey

我希望使用泽西分离以下参数

  1. Flightid
  2. numberofseats
  3. date

I tried all this code to separate but am failing miserably.

我尝试将所有这些代码分开但是失败了。

@GET
@Path(value = "/flight/{flightid}/{date}")
@Produces(MediaType.TEXT_PLAIN)
public Response bookFlight(@MatrixParam("numberofseats") int numberOfSeats,
        @PathParam(value = "flightid") int flightid,
        @PathParam(value = "date") String date) {
    //Logic
}

1 个解决方案

#1


0  

All matrix param examples I know carry them at the and of the URI. In your case the regex derived from your Path would eat up all URI parts and leave nothing for the @PathParam to capture. See section 3.7.3 of the JAX-RS 2.0 Spec.

我知道的所有矩阵参数示例都在URI和URI处进行。在你的情况下,从你的Path派生的正则表达式会占用所有URI部分,并且不会为@PathParam留下任何东西。请参阅JAX-RS 2.0规范的3.7.3节。

If possible, move theses parameters to the end.

如果可能,将这些参数移到最后。

Or parse flightid (which would contain the matrix params, I think) in your own code.

或者在你自己的代码中解析flightid(我认为它包含矩阵参数)。

#1


0  

All matrix param examples I know carry them at the and of the URI. In your case the regex derived from your Path would eat up all URI parts and leave nothing for the @PathParam to capture. See section 3.7.3 of the JAX-RS 2.0 Spec.

我知道的所有矩阵参数示例都在URI和URI处进行。在你的情况下,从你的Path派生的正则表达式会占用所有URI部分,并且不会为@PathParam留下任何东西。请参阅JAX-RS 2.0规范的3.7.3节。

If possible, move theses parameters to the end.

如果可能,将这些参数移到最后。

Or parse flightid (which would contain the matrix params, I think) in your own code.

或者在你自己的代码中解析flightid(我认为它包含矩阵参数)。