小编Ank*_*ter的帖子

如何将MultipartFile转换为字节流

//或者将多部分文件保存到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)

java spring hibernate

9
推荐指数
1
解决办法
3万
查看次数

方法Hibernate.createBlob()在Hibernate 4.0.1中已弃用,并已移至Hibernate.getLobCreator(会话会话).createBlob()

方法Hibernate.createBlob()Hibernate 4.0.1弃用并移至Hibernate.getLobCreator(Session session).createBlob().任何解决方案我应该在内部方法中传递什么getLobCreator(Session session),即代替Session,或任何其他解决方案,显示如何使用Spring和Hibernate检索并将图像保存到DB中.

java hibernate

6
推荐指数
1
解决办法
1万
查看次数

如何将 multipartfile 转换为 Blob 类型

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

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

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

hibernate

5
推荐指数
1
解决办法
9201
查看次数

标签 统计

hibernate ×3

java ×2

spring ×1