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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章