//将文件写入字节数组,可以将BOLB对应的实体类映射为字节数组类型,如下:
映射文件:
…………
//设置对应的映射type为binary 就可以存储字节数组
…………
对应的实体类:
public class FileBean {
…………
private byte[] fileContent; //直接映射为byte[]
…………
}
struts.xml
success,message
text/html
JAVA部分代码:
Java.io.File file = fileList.get(x);//获取前台传入的文件
byte[] fileByteArray = new byte[(int)file.length()] //根据文件长度创建字节数组
FileInputStream in = new FileInputStream(file);//获取流
in.read(fileByteArray,0,fileByteArray.length);//将文件流写入字节数组
//最后将字节数组通过Hibernate设置入库就OK 了
FileBean bean = new FileBean();
……
bean.setFileContent();