//或者将多部分文件保存到DB中的任何其他解决方案.我试过这种方式,但得到错误.
File fileOne = new File("file.getOrignalFileName");//what should be kept inside this method
byte[] bFile = new byte[(int) fileOne.length()];
try {
FileInputStream fileInputStream = new FileInputStream(fileOne);
//convert file into array of bytes
fileInputStream.read(bFile);
fileInputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
questionDao.saveImage(bFile);
Run Code Online (Sandbox Code Playgroud) 方法Hibernate.createBlob()从Hibernate 4.0.1弃用并移至Hibernate.getLobCreator(Session session).createBlob().任何解决方案我应该在内部方法中传递什么getLobCreator(Session session),即代替Session,或任何其他解决方案,显示如何使用Spring和Hibernate检索并将图像保存到DB中.
嗨,我正在将图像保存到数据库中,我将图像作为多部分并尝试转换为Blob类型。我做这个方法:
Blob blob=Hibernate.getLobCreator(sessionFactory.getCurrentSession()).createBlob(multipartFile.getInputStream(),multipartFile.getSize());
Run Code Online (Sandbox Code Playgroud)
但是得到Nullpointer Exception While Executing. 该文件无法将多部分转换为Blob任何其他方法将图像保存到数据库中。