1,数据库的字段用BLOB接受 hibernate映射blob
2,存储二维码
2,存储二维码
public static Blob StorageTwoDimensionCode(TbAssets assets) throws IOException{
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();//字节数组流
code.encoderQRCode(content, outputStream, "png",9);
//这里的Blob是java.sql包中的
Blob codeimg = Hibernate.createBlob(outputStream.toByteArray()); //outputStream转一个blob,这里可以接收InputStream和byte[]
outputStream.flush();
outputStream.close();
return codeimg; //返回一个blob
}
3,如果要读出来,在页面显示
public void showCodeImg(){
TbAssets assets = assetsService.getAssetsById(asid);
Blob codeimg = assets.getCodeImg();
try {
BufferedInputStream inputStream = new BufferedInputStream(codeimg.getBinaryStream()); //把BLOB