java restful @QueryParam获取JSP表单的值,为什么有的可以拿到,有的是null
Java代码 收藏代码
@Path("/users")
public class UserService {
@GET
@Path("/query")
public Response getUsers(@Context UriInfo info) {
String from = info.getQueryParameters().getFirst("from");
String to = info.getQueryParameters().getFirst("to");
List<String> orderBy = info.getQueryParameters().get("orderBy");
return Response
.status(200)
.entity("getUsers is called, from : " + from + ", to : " + to
+ ", orderBy" + orderBy.toString()).build();
}
URL;users/query?from=100&to=200&orderBy=age&orderBy=name
输出为:
getUsers is called, from : 100, to : 200, orderBy[age, name]
注意这里把orderby后的两个参数读入为LIST处理了.