1

我有一个 API。

@GET
@Path("picture")
@Produces("image/jpeg")
Response getPicture(@QueryParam("key") String key);

对应的服务。

@Override
public Response getPicture(String key) {
    try{
        byte[] image = service.getPicture(key);
        if (image == null) {

        }
        return Response.ok(new ByteArrayInputStream(image)).build();
    } catch (Exception e) {

    }
    return null;
}

我尝试返回 null 并返回 Response.ok(new ByteArrayInputStream(null)).build(),但我会得到一个异常。

当图像为空时,此方法返回什么?

4

0 回答 0