我想知道在JAX-RS中是否有注释/过滤器/拦截器功能,以便检测PUT或POST方法是否包含空请求体。
目前,我有一个方法,如果请求体为空,可能会抛出NPE异常。
@PUT
@Produces("application/json")
@Consumes("application/json")
@Path("/update/{id}")
public Response updateCustomer(@PathParam("id") final String customerIdStr, final CustomerJson customer) {
// if request body is empty -> customer == null
return Response.ok().build();
}
我可以检查客户
是否为null。但是,由于我有很多这样的方法,最好有一个过滤器来执行此类验证。
拜托了!