MYSQLデータベースにBLOBとしていくつかの画像をアップロードしました。次に、残りのWebサービスから取得したい画像を取得したいです。同じ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;
}
}
です。
現在のコード –
'SELECT'を表示してください。ループ。読む。 –
私はこのために休止状態と春を使用しています.ArrayListにオブジェクトを格納しているので、複数のイメージを格納するために使用できます。 –