spring主配置文件:
<!-- 配置ibatis -->
<bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
<property name="configLocation"
value="classpath:sql-map-config.xml" />
<property name="dataSource" ref="dataSource" />
<property name="lobHandler" ref="lobHandler"></property><!-- add by shizhan -->
</bean>
<bean id="lobHandler" class="org.springframework.jdbc.support.lob.DefaultLobHandler" lazy-init="true"> </bean>
sql-map-config.xml配置如下:
<typeHandler jdbcType="BLOB" javaType="[B" callback="org.springframework.orm.ibatis.support.BlobByteArrayTypeHandler" />
<sqlMap resource="com/techown/wms/mp/atomic/dao/ibatisblob-sqlmap.xml" />
ibatisblob-sqlmap.xml的配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sqlMap PUBLIC "-//iBATIS.com//DTD Sql Map 2.0//EN" "http://www.ibatis.com/dtd/sql-map-2.dtd" >
<sqlMap namespace="ibatisblob">
<typeAlias alias="ibatisblob" type="com.techown.wms.mp.atomic.bean.ClientPackageDetail" />
<insert id="insertblob" parameterClass="ibatisblob">
insert into _wms_client_package_details(client_package_id,fullpathfilename,fileMD5)
values(#clientPackageId#,#fullPathFilename#,#fileMD5:BLOB#)
</insert>
</sqlMap>
mysql表结构:
-- Table "_wms_client_package_details" DDL
CREATE TABLE `_wms_client_package_details` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`client_package_id` int(11) DEFAULT NULL,
`fullpathfilename` varchar(1000) DEFAULT NULL,
`fileMD5` blob,
`insertimte` datetime DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=335 DEFAULT CHARSET=utf8;