Java 要休息的图像字节数
我已经将图像存储在数据库中,我希望它通过rest公开。最好的方法是什么Java 要休息的图像字节数,java,jakarta-ee,rest,Java,Jakarta Ee,Rest,我已经将图像存储在数据库中,我希望它通过rest公开。最好的方法是什么 @Path("/image/{imageId}.jpeg") @Stateless @Produces({"image/jpeg"}) public class ImageSource{ @PersistenceContext EntityManager em; @GET public /* what */ getImage(@PathParam("imageId") Long imageId) throws IO
@Path("/image/{imageId}.jpeg")
@Stateless
@Produces({"image/jpeg"})
public class ImageSource{
@PersistenceContext
EntityManager em;
@GET
public /* what */ getImage(@PathParam("imageId") Long imageId) throws IOException{
byte[] image = em.find(Entity1.class, imageId).getImage();
// something here
}
}
您需要一个由生成器方法创建的响应 看
您需要一个由生成器方法创建的响应 看
public Response getImage(@PathParam("imageId") Long imageId) throws IOException{
...
return Response.ok( image, mediatype).build();
}