mybatis 读取blob数据

mybatis读取blob数据过程:

1、从数据库中读出blob数据类型,用pojo中的byte[]接收。

2、把文件保存成文件(或者变成base64也行)。

Customer.java

public class Customer {
private String cuscode;
private byte[] qrcode;
public String getCuscode() {
return cuscode;
} public void setCuscode(String cuscode) {
this.cuscode = cuscode;
} public byte[] getQrcode() {
return qrcode;
} public void setQrcode(byte[] qrcode) {
this.qrcode = qrcode;
}

}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20

springmvc中的请求

@RequestMapping(value = "/web/showerweima")
@ResponseBody
public String showerweima() {
Map<String,Object> params = new HashMap<String, Object>();
params.put("cuscode","vvcc");
Map<String,Object> resMap = memberManagementServices.getQrcode(params);
byte[] buffer = (byte[])resMap.get("imgstr");
File file = new File("d:/temp/cccc.png");
FileOutputStream fos = null;
try {
fos = new FileOutputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
BufferedOutputStream bos = new BufferedOutputStream(fos);
try {
bos.write(buffer);
} catch (IOException e) {
e.printStackTrace();
}
return "123";
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22

对应的dao层

Customer getQrcode(Map<String, Object> params);
  • 1

xml文件中的内容:

<select id="getQrcode" parameterType="map" resultType="com.xueyou.model.Customer">
SELECT * from t_customer where cuscode = #{cuscode}
</select>
  • 1
  • 2
  • 3

这样能够把图片保存成文件。

mybatis读取blob类型的更多相关文章

  1. mybatis oracle BLOB类型字段保存与读取

    一.BLOB字段 BLOB是指二进制大对象也就是英文Binary Large Object的所写,而CLOB是指大字符对象也就是英文Character Large Object的所写.其中BLOB是用 ...

  2. 插入与读取Blob类型数据

    BlobTest package com.aff.PreparedStatement; import java.io.File; import java.io.FileInputStream; imp ...

  3. mybatis 处理CLOB/BLOB类型数据

    BLOB和CLOB都是大字段类型. BLOB是按二进制来存储的,而CLOB是可以直接存储文字的. 通常像图片.文件.音乐等信息就用BLOB字段来存储,先将文件转为二进制再存储进去.文章或者是较长的文字 ...

  4. 读取数据库Blob类型的文本数据

    开发一个查询功能时,遇到了一个ORM的问题:数据库字段是 Blob 类型,里面实际存储的是文本数据,Java 后端代码中用字符串 String 类型去接收这个字段的数据时,报错,提示没有对应的sett ...

  5. 读取和写入blob类型数据

    读写oracle  blob类型 http://zyw090111.iteye.com/blog/607869 http://blog.csdn.net/jeryjeryjery/article/de ...

  6. <十>JDBC_处理Blob类型数据

    /*  * 读取BLOB数据:  *  使用getBlob方法读取到Blob对象  *  调用Blob的getBinaryStream(方法得到输入流,在使用IO操作  * */ @Test publ ...

  7. MyBatis jdbcType常用类型

    MyBatis jdbcType常用类型 jdbcType与javaType对应关系 javaType jdbctype CHAR String VARCHAR String LONGVARCHAR ...

  8. 使用PreparedStatement向数据表中插入、修改、删除、获取Blob类型的数据

    使用PreparedStatement向数据表中插入.修改.删除.获取Blob类型的数据 2014-09-07 20:17 Blob介绍 BLOB类型的字段用于存储二进制数据 MySQL中,BLOB是 ...

  9. 【转】Oracle中插入和取出图片(用BLOB类型)

    原文地址:http://czllfy.iteye.com/blog/66737 其他参考资料地址:http://lavasoft.blog.51cto.com/62575/321882/ 要在orac ...

  10. mysql存取blob类型数据

    参考网址:http://www.cnblogs.com/jway1101/p/5815658.html 首先是建表语句,需要实现将表建立好. CREATE TABLE `blobtest` ( `pr ...

随机推荐

  1. 基础文之-----typeof 和 instanceof

    为了巩固基础,我会通过实例来详细说明,让我们一起搞懂 typeof 和 instanceof. <!DOCTYPE html> <html lang="en"&g ...

  2. 《HelloGitHub》第 82 期

    兴趣是最好的老师,HelloGitHub 让你对编程感兴趣! 简介 HelloGitHub 分享 GitHub 上有趣.入门级的开源项目. https://github.com/521xueweiha ...

  3. Fabric2.x中Raft共识算法核心数据结构

    一.共识算法可插拔的代码体现Chain接口 Hyperledger Fabric的共识算法是可插拔的,在代码上体现为Chain接口,所有不同的共识算法均可根据Chain接口进行具体实现,目前fabri ...

  4. 论文翻译:2022_Time-Shift Modeling-Based Hear-Through System for In-Ear Headphones

    论文地址:基于时移建模的入耳式耳机透听系统 引用格式: 摘要 透传(hear-through,HT)技术是通过增强耳机佩戴者对环境声音的感知来主动补偿被动隔离的.耳机中的材料会减少声音 500Hz以上 ...

  5. .net core 阿里云接口之将指定的OSS文件下载到流

    紧接上文,.net core 阿里云接口之获取临时访问凭证_SunshineGGB的博客-CSDN博客 本文继续阿里云接口调用,将指定的OSS文件下载到流. 直接上代码: /// <summar ...

  6. python3中,isinstance() 函数

    #isinstance() 函数来判断一个对象是否是一个已知的类型,类似 type(). #返回值:如果对象的类型与参数二的类型相同则返回True,否则返回False 使用isinstance函数的实 ...

  7. 基于 Hugging Face Datasets 和 Transformers 的图像相似性搜索

    基于 HuggingFace Datasets 和 Transformers 的图像相似性搜索 通过本文,你将学习使用 Transformers 构建图像相似性搜索系统.找出查询图像和潜在候选图像之间 ...

  8. Typescript 回调函数、事件侦听的类型定义与注释--拾人牙慧

    实际项目中会运到的 Typescript 回调函数.事件侦听的类型定义,如果刚碰到会一脸蒙真的,我就是 这是第一次我自己对 Typescript 记录学习,所以得先说一下我与 Typescript 的 ...

  9. Balanced Team

    https://vjudge.net/problem/CodeForces-1133C 题意:在数组中找出一段  每两个元素差值不大于5的这段元素个数的最大值. 1 #include <iost ...

  10. 小程序动态class与动态style的写法:

    style = "opacity :{{num}}" class = "vp {{opacity == 0 ? 'opacity1':''}}"