成功解決MyBatis查詢MySQL中text類型的大字段爲空,selectByExampleWithBLOBs與selectByExample的區別

一、問題復現:

通過selectByExample查詢planJonsData時值爲null,但通過selectByExampleWithBLOBs不改變查詢條件,查詢的結果值不爲空

在這裏插入圖片描述
在這裏插入圖片描述

二、selectByExampleWithBLOBs與selectByExample的區別

對比兩個查詢方法,不難發現selectByExampleWithBLOBs 除了具有selectByExample的屬性,在resultMap 裏還額外定義一行 jdbcType=“LONGVARCHAR”,用於長文本查詢,所以當數據表中有text等存儲長文本類型時,最好在查詢、更新時能使用帶WithBLOBs結尾的方法,另外selectByPrimaryKey的resultMap也帶有WithBLOBs。

  <resultMap id="BaseResultMap" type="com.xxx.CooperationModel">
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="gmt_create" jdbcType="TIMESTAMP" property="gmtCreate" />
    <result column="gmt_modified" jdbcType="TIMESTAMP" property="gmtModified" />
	...
  </resultMap>
  
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.xxx.CooperationModel">

    <result column="plan_json_data" jdbcType="LONGVARCHAR" property="planJsonData" />
  </resultMap>
  
  
<select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="ResultMapWithBLOBs">
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章