小编Nel*_*ess的帖子

从REST GET服务调用获取整个查询字符串

有没有一种方法可以获取整个查询字符串而不进行解析?如:

http://localhost:8080/spring-rest/ex/bars?id=100,150&name=abc,efg
Run Code Online (Sandbox Code Playgroud)

我想得到一切吗?作为一个字符串。是的,我稍后会对其进行解析,但这使我的控制器和所有后续代码更加通用。

到目前为止,我已经尝试使用@ PathParam,@ RequestParam以及@Context UriInfo,结果如下。但是我似乎无法理解整个字符串。这就是我要的:

id=100,150&name=abc,efg
Run Code Online (Sandbox Code Playgroud)

使用curl @PathParam使用

http:// localhost:8080 / spring-rest / ex / bars / id = 100,150&name = abc,efg

产生id = 100,150

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  @Path("/spring-rest/ex/qstring/{qString}")
  public String getStuffAsParam ( @PathParam("qstring") String qString) { 
         ...
  }
Run Code Online (Sandbox Code Playgroud)

@RequestParam使用

http:// localhost:8080 / spring-rest / ex / bars?id = 100,150&name = abc,efg

给出无法识别的名称。

http:// localhost:8080 / spring-rest / ex / bars?id = 100,150; name = abc,efg

产生异常。

  @GET
  @Produces(MediaType.TEXT_PLAIN)
  @Path("/spring-rest/ex/qstring")
  public String getStuffAsMapping (@RequestParam (value ="qstring", required = false) …
Run Code Online (Sandbox Code Playgroud)

java rest spring spring-mvc

4
推荐指数
1
解决办法
4811
查看次数

标签 统计

java ×1

rest ×1

spring ×1

spring-mvc ×1