二维码写入到数据库

本文介绍了如何使用Hibernate将二维码数据写入数据库,并探讨了可能出现的异常处理及如何从数据库读取数据在页面上展示。
摘要由CSDN通过智能技术生成
1,数据库的字段用BLOB接受  hibernate映射blob

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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值