[英]How to retrieve multiple blob images from database
嗨,我正在使用Spring MVC和Hibernate。 我想從數據庫中檢索多個blob圖像,並希望在jsp中顯示。 我嘗試了很多,但沒有得到富有成效的答案。 如果有人提供鏈接或示例代碼,那對我來說太好了。
如果您已經在使用spring,還可以查看spring數據和數據存儲庫( http://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories )。
那里有很多例子,它應該如何運作:)
如果您使用最新版本,則可以流式傳輸結果。 這樣,如果您遇到性能問題,就可以異步加載圖像。
我在服務器端使用此代碼,它對我有用
彈簧控制器
@RequestMapping(value ="/getImages", method = RequestMethod.GET)
@ResponseBody
public List<Product> getStateList(HttpServletResponse response, HttpServletRequest request) {
List<Product> image = imageService.getImageList();
List<Product> imageList= new ArrayList<Product>();
for (Product m : new ArrayList<Product>(image)) {
String base64Encoded = javax.xml.bind.DatatypeConverter.printBase64Binary(m.getImage());
Product imagepath = new Product();
imagepath.setImagePath(base64Encoded);
imagepath.setItemName(m.getItemName());
imageList.add(imagepath);
}
return imageList;
}
道
public List<Product> getImageList() {
String getImageQuery = "FROM Product";
Query query = sessionFactory.getCurrentSession().createQuery(getImageQuery);
@SuppressWarnings("unchecked")
List<Product> imgList = query.list();
return imgList;
}
型號類別
@Entity
@Table(name="imageUpload")
public class ImageUpload {
@Id
@Column(name="eloraId")
private int eloraId;
@Column(name="password")
private String password;
@Column(name="ownerName")
private String ownerName;
@Column(name="registeredId",columnDefinition="mediumblob")
private byte[] registeredId;
@Column(name="hospPanCard")
private String hospPanCard;
@Column(name="hospRegCert",columnDefinition="mediumblob")
private byte[] hospRegCert;
@Column(name="ownerPanCard",columnDefinition="mediumblob")
private byte[] ownerPanCard;
@Column(name="ownerselfDec",columnDefinition="mediumblob")
private byte[] ownerselfDec;
@Column(name="ownerAddProof",columnDefinition="mediumblob")
private byte[] ownerAddProof;
@Transient
private String statusMessage;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.