MyBatis Generator对于mysql text类型数据的处理||MyBatis生成的selectByExample方法获取text类型数据得到空值...

Mybatis自动生成的Xml文件,text数据类型会默认产生XXWithBlobs的方法,用以获取含有该类型的数据

  • 所以,读取含有text类型的数据的时候,应该使用XXWithBlobs的方法,否则会获取到空值
  • 其次,只能修改数据类型了,改用varchar了

以下是MyBatis对于数据类型映射的操作解析

  • 如下,可以看到MyBatis对于类型的处理:

表数据,其中introductiontext类型数据

1411662-20190422013147787-2056617408.png

MyBatis Generator生成的mapper.xml片段:

  <resultMap id="BaseResultMap" type="com.liantao.bookMS.entity.Book">
    <id column="book_id" jdbcType="BIGINT" property="bookId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="author" jdbcType="VARCHAR" property="author" />
    <result column="publish" jdbcType="VARCHAR" property="publish" />
    <result column="ISBN" jdbcType="VARCHAR" property="isbn" />
    <result column="language" jdbcType="VARCHAR" property="language" />
    <result column="price" jdbcType="DECIMAL" property="price" />
    <result column="pubdate" jdbcType="DATE" property="pubdate" />
    <result column="class_id" jdbcType="INTEGER" property="classId" />
    <result column="pressmark" jdbcType="INTEGER" property="pressmark" />
    <result column="state" jdbcType="SMALLINT" property="state" />
  </resultMap>
  <resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.liantao.bookMS.entity.Book">
    <result column="introduction" jdbcType="LONGVARCHAR" property="introduction" />
  </resultMap>

对于text类型的映射是 jdbcType="LONGVARCHAR",普通类型处理则为VARCHAR,DATE,BIGINT之类的。

修改数据类型为varchar后的maper.xml应该为:

  <resultMap id="BaseResultMap" type="com.liantao.bookMS.entity.Book">
    <id column="book_id" jdbcType="BIGINT" property="bookId" />
    <result column="name" jdbcType="VARCHAR" property="name" />
    <result column="author" jdbcType="VARCHAR" property="author" />
    <result column="publish" jdbcType="VARCHAR" property="publish" />
    <result column="ISBN" jdbcType="VARCHAR" property="isbn" />
    <result column="language" jdbcType="VARCHAR" property="language" />
    <result column="price" jdbcType="DECIMAL" property="price" />
    <result column="pubdate" jdbcType="DATE" property="pubdate" />
    <result column="class_id" jdbcType="INTEGER" property="classId" />
    <result column="pressmark" jdbcType="INTEGER" property="pressmark" />
    <result column="state" jdbcType="SMALLINT" property="state" />
    <result column="introduction" jdbcType="VARCHAR" property="introduction" />
  </resultMap>

PS:我不知道为什么直接改不能生效,要改了数据库在用mbg.java在生成一次才行,如有知晓请告知 3q

END

转载于:https://www.cnblogs.com/famine/p/10748035.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值