1.創建用於接收blob類型的實體類 1 @Getter 2 @Setter 3 public class FileEntity implements Serializable { 4 private static final long serialVersionUID = -55445605143 ...
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 xml 文件中 配置resultMap
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[] 並賦值給實體類