如何将 multipartfile 转换为 Blob 类型

Ank*_*ter 5 hibernate

嗨,我正在将图像保存到数据库中,我将图像作为多部分并尝试转换为Blob类型。我做这个方法:

Blob blob=Hibernate.getLobCreator(sessionFactory.getCurrentSession()).createBlob(multipartFile.getInputStream(),multipartFile.getSize());
Run Code Online (Sandbox Code Playgroud)

但是得到Nullpointer Exception While Executing. 该文件无法将多部分转换为Blob任何其他方法将图像保存到数据库中。

Har*_*jar 4

MultipartFile savedFile;
savedFile=itemView.getImgFile();//file from model attribute 
Blob blob=Hibernate.createBlob(savedFile.getInputStream()); // hibernate method for create blob 
//Save method will be call here 
Run Code Online (Sandbox Code Playgroud)

http://viralpatel.net/blogs/tutorial-save-get-blob-object-spring-3-mvc-hibernate/ 我按照上面的教程进行操作

  • 当我使用 `createBlob()` 方法时,我收到此错误 `The method createBlob(InputStream) is undefined for the type Hibernate`,因为它已被弃用并且在 Hibernate 版本 4 中。 (3认同)