zoukankan      html  css  js  c++  java
  • 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

  • 相关阅读:
    转:用十条命令在一分钟内检查Linux服务器性能
    android适配的努力
    转: Android Studio你不知道的调试技巧
    编码处理过滤器
    PageBean分页组件
    BaseServlet方法分发
    SQLHelper、DBUtil终极封装
    JavaEE面试题库
    Servlet、JSP选择题(2)
    Servlet、JSP选择题
  • 原文地址:https://www.cnblogs.com/famine/p/10748035.html
Copyright © 2011-2022 走看看