MyBatis blob与二进制转换实力
1.实体中定义byte数组对象
private byte[] feature;//重点,类型为byte
2、mybatis mapper对应的xml中配置
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.xxx.firearms.mapper.BottomFeatureMapper">
<resultMap type="BottomFeature" id="BottomFeatureResult">
<!--注意1:javaType jdbcType typeHandler-->
<result property="feature" column="feature" javaType="java.sql.Blob" jdbcType="BLOB" typeHandler="org.apache.ibatis.type.BlobTypeHandler"/>**
</resultMap>
<sql id="xxxsql">
select feature from xxxxx
</sql>
<insert id="insertBottomFeature" parameterType="BottomFeature">
insert into xxxxx
(
feature)
values
<!--注意2:-->
#{feature,jdbcType=BLOB} )#重点,加jdbcType
</insert>
</mapper>
3.自定义转换时继承BaseTypeHandler