今天使用selectByExample 取数据库中取数据,发现有一个字段始终取不出来,参考文章,通过检查发现该字段是text类型。
将调用selectByExample方法改为调用selectByExampleWithBLOBs 方法就能取出数据。
<select id="selectByExample" parameterType="com.pojo.TbItemParamExample" resultMap="BaseResultMap">
<select id="selectByExampleWithBLOBs" parameterType="com.pojo.TbItemParamExample" resultMap="ResultMapWithBLOBs">
<resultMap id="BaseResultMap" type="com.pojo.TbItemParam">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Aug 27 16:29:38 CST 2018.
-->
<id column="id" jdbcType="BIGINT" property="id" />
<result column="item_cat_id" jdbcType="BIGINT" property="itemCatId" />
<result column="created" jdbcType="TIMESTAMP" property="created" />
<result column="updated" jdbcType="TIMESTAMP" property="updated" />
</resultMap>
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.pojo.TbItemParam">
<!--
WARNING - @mbg.generated
This element is automatically generated by MyBatis Generator, do not modify.
This element was generated on Mon Aug 27 16:29:38 CST 2018.
-->
<result column="param_data" jdbcType="LONGVARCHAR" property="paramData" />
</resultMap>
可以看出selectByExampleWithBLOBs的返回值ResultMapWithBLOBs是继承自selectByExample的返回值BaseResultMap,他拥有BaseResultMap的全部属性,并且拥有自己特有的属性param_data,而数据库param_data的类型为text(bigvarchar),text的最大长度约为64KB,所以要使用blob。
数据库有四种text,分别对应四种blob。
TinyBlob 最大长度255个字元(2^8-1) ==>255
TinyText 最大长度255个字元(2^8-1)
Blob 最大长度65535个字元(2^16-1) ==>64KB
Text 最大长度65535个字元(2^16-1)
MediumBlob 最大长度 16777215 个字元(2^24-1) ==>16MB
MediumText 最大长度 16777215 个字元(2^24-1)
LongBlob 最大长度4294967295个字元 (2^32-1) ==>4GB
LongText 最大长度4294967295个字元 (2^32-1)
---------------------
原文:https://blog.csdn.net/u013430054/article/details/82416343