成功解决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">

猜你喜欢

转载自blog.csdn.net/loulanyue_/article/details/105821084