ibatis处理blob字段和clob字段

在项目中,使用Ibatis处理包含Blob和Clob字段的数据时遇到问题。解决方案是在Ibatis的配置文件中,针对Blob字段使用`BlobByteArrayTypeHandler`,对于Clob字段使用`ClobStringTypeHandler`。对应的JavaBean中,Blob字段为byte数组,Clob字段为字符串。在提供WebService接口时,由于需要序列化,因此不能直接以流形式传输。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最经项目的一个功能需要提供webservice接口个别的系统调用,数据库层采用了ibatis,

ibatis在处理blob字段的时候遇到了问题,后面解决了

解决办法采用ibatis自己的自动转换  配置文件如下:

<resultMap id="BolbStorage" class="TblobstorageDTO" >
  <result property="storageid" column="storageid"/>
  <result property="category" column="category"/>
  <result property="remindno" column="remindno"/>
  <result property="filename" column="filename"/>
  <result property="accessory" column="accessory" typeHandler="org.springframework.orm.ibatis.support.BlobByteArrayTypeHandler"/>这个是blob字段

<result property="remcontent" column="remcontent" typeHandler="org.springframework.orm.ibatis.support.ClobStringTypeHandler"/>这个字段是clob字段
  <result property="filesize" column="filesize"/>
  <result property="creator" column="creator"/>
  <result property="createdate" column="createdate"/>
  <result property="securitylevel" column="securitylevel"/>
  <result property="isuse" column="isuse"/>
  <result property="type" column="type"/>
  <result property="memo" column="memo"/>
  <result property="fileid" column="fileid"/>
  </resultMap>
  <sql id="queryBolbStorage_Where">
  <isNotEmpty prepend="and" property="category" >
        c_catalog = #category#
      </isNotEmpty>
      <isNotEmpty prepend="and" property="remindno" >
        c_subkeyid = #remindno#
      </isNotEmpty>
      <isNotEmpty prepend="and" property="ctorageid" >
        l_storageid = #ctorageid# 
      </isNotEmpty>
      <isNotEmpty prepend="and" property="isuse" >
        c_isuse = #isuse#
      </isNotEmpty>
  </sql>
  <select id="queryBolbStorage" resultMap="BolbStorage">
  select t.l_storageid storageid,
  t.c_catalog category,
  t.c_subkeyid remindno,
  t.c_filename filename,
  t.b_accessory  accessory,
  t.l_filesize filesize,
  t.c_creator creator,
  t.d_createdate createdate,
    t.c_securitylevel securitylevel,
    t.c_isuse isuse, 
    t.c_type type,
    t.c_memo memo,
    t.c_fileid fileid from tblobstorage t
    <dynamic prepend="where" >
    <include refid="queryBolbStorage_Where"/>
</dynamic>
  </select>

blob字段的对于的javabean是数组  private byte[] accessory;

clob字段对应的javabean是字符串 private String remcontent;

用于提供的webservice数组,需要实现序列化才可以在网上传输,所以采用的数组不能直接以流的形式。


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值