Passing indefinite Query Parameters with RESTful URL and reading them in RESTEasy

[亡魂溺海] 提交于 2019-12-01 08:59:24

The best thing to do in this case would be using a DTO containing all the fields of your search criteria. For example, you mentioned 4 distinct parameters.

  1. Book Name (bookName)
  2. Author Name (authorName)
  3. Publisher Name (pubName)
  4. ISBN (isbn)

Create a DTO containing the fields having the following annotations for every property you want to map the parameters to:

public class CriteriaDTO{

  @QueryParam("isbn")
  private String isbn;
.
.

Other getter and setters of other properties

}

Here is a method doing that for your reference:

@GET
@Produces("application/json")
@Path("/searchBooks")
public ResultDTO search(@Form CriteriaDTO dto){
}

using following URL will populate the CriteriaDTO's property isbn automatically:

your.server.ip:port/URL/Mapping/searchBooks?isbn=123456789&pubName=testing

jett

A similar question was asked here: How do you map multiple query parameters to the fields of a bean on Jersey GET request?

I went with kensen john's answer (UriInfo) instead. It allowed to just iterate through a set to check which parameters were passed.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!