我已经在MYSQL数据库中上传了一些图像作为BLOB.Now我想通过其余的Web服务和java.I检索它我能够检索一个图像。但我如何检索多个在同一time.What图像可能是对此最好的解决办法吗?我的数据库,它只是像这样使用java从MYSQL数据库检索多个图像
任何帮助将提前appreciated.Thanks。
我DAO类方法是
public Response downloadById(int employeeId) {
ResponseBuilder response=null;
@SuppressWarnings("unchecked")
ArrayList<UserProfile> userProfile=(ArrayList<UserProfile>)getHibernateTemplate().find("from UserProfile where employeeId=?",employeeId);
for(UserProfile user:userProfile){
byte[] image = user.getProfilePic();
try{
//String tomcatDir = System.getProperty("catalina.home");
FileOutputStream fos = new FileOutputStream("D:/img/"+employeeId+".png");
File file=new File("D:/img/"+employeeId+".png");
response = Response.ok((Object) file);
response.header("Content-Disposition","attachment; filename=\"javatpoint_image.png\"");
fos.write(image);
fos.close();
}catch(Exception e){
e.printStackTrace();
}
}
return response.build();
}
我Bean类是
public class UserProfile {
private int employeeId;
private String role;
private byte[] profilePic;
public int getEmployeeId() {
return employeeId;
}
public void setEmployeeId(int employeeId) {
this.employeeId = employeeId;
}
public String getRole() {
return role;
}
public void setRole(String role) {
this.role = role;
}
public byte[] getProfilePic() {
return profilePic;
}
public void setProfilePic(byte[] profilePic) {
this.profilePic = profilePic;
}
}
我把图像文件夹中,并从那里我acessing它。
请显示您的当前代码 –
'SELECT'。循环。读。 –
我正在使用hibernate和spring。因为我们正在将对象存储在ArrayList.What可以用于存储多个图像。 –