我将图片插入到Mysql数据库中,图片将被保存。如何使用spring从Mysql数据库中检索图像?
File file = new File("G:/photos/New Folder (2)/www.geocities.com_cliknenjoy_lakshmimittal.jpg");
byte[] bFile = new byte[(int) file.length()];
try {
FileInputStream fileInputStream = new FileInputStream(file);
fileInputStream.read(bFile);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
inpatient.setImagefile(bFile);
我在mysql中使用blob数据类型。
private byte[] imagefile;
public byte[] getImagefile() {
return imagefile;
}
public void setImagefile(byte[] imagefile) {
this.imagefile = imagefile;
}
现在我无法从mysqldatabase打开图像文件,我该如何打开这一个?
你是说你在使用Blob,但在你的例子中我可以看到byte []? – 2013-03-27 09:39:07
您尚未展示如何存储它或如何阅读它。 – 2013-03-27 14:16:07
雅我存储的字节[],但我会存储blob数据类型使用在MySQL中,我可以打开,看到从MySQL的图像。但我需要通过编码打开,图像显示从数据库。我怎样做? – 2013-03-28 08:17:46