Galera do Guj, estou com um problema que, com certeza, vocês irão me ajudar, o problema é o seguinte: estou salvando imagem direto no banco de dados, entretanto não estou conseguindo fazer com que a foto seja exibida na página. abaixo vou postar os códigos:
Minha entidade
@Entity(name = "photo")
public class Photo implements Serializable{
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name="id")
private Integer id;
@Column(name="photo")
private byte[] photo;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public byte[] getPhoto() {
return photo;
}
public void setPhoto(byte[] photo) {
this.photo = photo;
}
}
public void savePhoto() throws IOException {
File file = new File("C:\\Users\\WILLIANBALDEZ.AP\\Pictures\\foto.jpg");
FileInputStream fis = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
fis.read(bytes);
photo.setPhoto(bytes);
save(photo);
}
public void savePhoto() throws IOException {
imagemB = ImageIO.read(new File("C:/Users/WILLIANBALDEZ.AP/Pictures/FOTO.jpg"));
ByteArrayOutputStream bytesImg = new ByteArrayOutputStream();
ImageIO.write((BufferedImage) imagemB, "jpg", bytesImg);//seta a imagem para bytesImg
bytesImg.flush();//limpa a variável
byte[] byteArray = bytesImg.toByteArray();//Converte ByteArrayOutputStream para byte[]
bytesImg.close();//fecha a conversão
photo.setPhoto(byteArray);
save(photo);
}
Agora a duvida é como exibir as imagens na Página WEB.
Desde já agradeço.