我正在处理文件上传。我的 Controller 中有这段代码。
try {
Blob blob = Hibernate.createBlob(file.getInputStream()); // error here!!
document.setFilename(file.getOriginalFilename());
document.setContent(blob);
document.setContentType(file.getContentType());
} catch (IOException e) {
e.printStackTrace();
}
错误是,Hibernate 类型的 createBlob(InputStream) 方法未定义。我正在使用 Hibernate 4,但其中似乎不存在此方法。我该如何解决?
最佳答案
嘿,你应该使用的是:
try {
Blob blob =Hibernate.getLobCreator(HibernateUtil.getSessionFactory().getCurrentSession()).createBlob(file.getInputStream());
document.setFilename(file.getOriginalFilename());
document.setContent(blob);
document.setContentType(file.getContentType());
} catch (IOException e) {
e.printStackTrace();
}
我想这应该可以做到
关于java - Hibernate.createBlob(file.getInputStream()) 的替代方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36837057/