MyBatis中selectByExample和selectByExampleWithBLOBs区别

MyBatis中selectByExample和selectByExampleWithBLOBs区别

先贴一段自动生成的Mapper代码

  <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,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://www.cnblogs.com/pureEve/p/6015000.html
https://www.jianshu.com/p/492ffd296a74?utm_campaign

猜你喜欢

转载自blog.51cto.com/12434484/2323778