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


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

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

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

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

    表数据,其中introductiontext类型数据

    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

  • 相关阅读:
    【笔记】ubuntu下搜狗输入法的安装(12.04和14.04都会提到,侧重前者)
    【笔记,转载】c++ string与int的转化
    【笔记】关于字符串相加
    【转载】 C++ fstream文件流读写文件操作详解
    【转载】大数据分析的众包平台—Kaggle (如有侵权,请联系我)
    【转载】 生成模型与判别模型
    【杂记】递归缩写
    【笔记】给自己的博客侧栏添加小时钟
    【笔记】改变vim或者终端terminal的光标形状。光标变细了之后看起来爽快多了!
    【笔记】 使用GNU profiler查找性能瓶颈,查看代码中每个函数所消耗的时间
  • 原文地址:https://www.cnblogs.com/famine/p/10748035.html
Copyright © 2020-2023  润新知