您好我正在使用Spring mvc和hibernate。我想从数据库中检索多个blob图像,并希望在jsp中显示。我尝试了很多,但没有得到富有成效的答案。如果有人提供链接或示例代码,那对我来说会很棒。
答案 0 :(得分:1)
如果您已经使用spring,您还可以查看spring数据和数据存储库(http://docs.spring.io/spring-data/commons/docs/current/reference/html/#repositories)。
有很多例子,它应该如何看待行动:)
如果您使用最新版本,则可以流式传输结果。如果遇到性能问题,可以将图像加载为异步。
答案 1 :(得分:0)
我正在使用服务器端此代码它适用于我
Spring Controller
@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;
}
DAO
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;
}