由于hibernate4废弃hibernate.createClob,只能采用getLobHelper获取,Hibernate4以下的版本均可采用hibernate.createClob
@Transactional
public int uploadCap(CommonsMultipartFile file,CapPackage capPackage){
InputStream fis=null;
byte[] content=null;
Transaction transaction=null;
Session session=null;
session = this.getSessionFactory().openSession();
try {
//将磁盘文件读入到输入流
fis=file.getInputStream();//new FileInputStream("C:\\Users\\wangkk\\Desktop\\1.sql");
//将输入流中的内容存储到字节数组中
content=new byte[fis.available()];
fis.read(content);
Blob blobContent= session.getLobHelper().createBlob(content);
capPackage.setCapContent(blobContent);
this.getHibernateTemplate().save(capPackage);
return 200;
} catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return 0;
}