【发布时间】:2018-04-14 11:47:09
【问题描述】:
任何替代方案,因为我认为我无法重载 REST 请求。 但我也想按年份或其他任何方式进行搜索。 我读过我应该使用 RequestMapping 或类似的东西,但我不使用 spring。我想将查询字符串(带有所有过滤器)传递给该方法。关于我如何只有一个唯一的方法来做到这一点的任何想法?
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getMovieByName(@Context HttpServletRequest req, @QueryParam("text") String name) {
if (!checkLoggedIn(req)) {
throw new WebApplicationException("User not logged.");
}
return buildResponse(movieService.getMovieByName(name));
}
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public Response getNumberOfMovies(@Context HttpServletRequest req, @QueryParam("n_movies") Integer total) {
if (!checkLoggedIn(req)) {
throw new WebApplicationException("User not logged.");
}
return buildResponse(movieService.getNumberOfMovies(total));
}
【问题讨论】:
-
在一种方法中使用多个 QueryParam 还不够吗?