2020-05-15

java +mybatis 获取oracle存储的blob对象

java +mybatis 获取oracle存储的blob对象


1.创建用于接收blob类型的实体类

 1 @Getter 2 @Setter 3 public class FileEntity implements Serializable { 4  private static final long serialVersionUID = -5544560514334406226L; 5  //附件类型 6  private String fileType; 7  //附件 8  private byte[] blob; 9 }

2.在mybaits

1 <resultMap id="fileResultMap" type="com.domains.entity.FileEntity">2   <result column="BB10" property="fileType"></result>3   <result column="FJ" property="blob" jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BlobTypeHandler"></result>4  </resultMap>

3.SQL语句

1 <select id="getBlob" resultMap="fileEntityResultMap">2   select BB10,FJ from cb10 where cb100=#{uuid}3  </select>

blob 类型或被

org.apache.ibatis.type.BlobTypeHandler 转换成 byte[] 并赋值给实体类

No comments:

Post a Comment