Spring and MyBatis integrate to automatically generate text type pit in the code

Keywords: Mybatis MySQL Java xml

After Spring and MyBatis are integrated, dao and mapper configuration files are generated by using the automatic code generation tool. The steps are as follows (take Intelli idea as an example).

  1. Write the generate code configuration file generatorConfig.xml.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"

    <classPathEntry location="D:\dev\maven\repository\mysql\mysql-connector-java\5.1.39\mysql-connector-java-5.1.39.jar"/>
    <context id="DB2Tables" defaultModelType="flat" targetRuntime="MyBatis3">
            <property name="suppressDate" value="true"/>
            <!-- Remove automatically generated comments or not true: Yes: false:no -->
            <property name="suppressAllComments" value="false"/>
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"

            <property name="forceBigDecimals" value="false"/>

        <!-- Package name and location of the build model  -->
        <javaModelGenerator targetPackage="com.cx.elearnning.model"
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        <!-- generate xml -->
        <sqlMapGenerator targetPackage="/"
            <property name="enableSubPackages" value="true"/>
        <!-- generate Mapper -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.cx.elearnning.dao"
            <property name="enableSubPackages" value="true"/>
      <!--Automatically generated table names and corresponding model name-->
        <table tableName="sys_user" domainObjectName="SysUser"></table>

  1. Configure maven to run the command as follows.

    maven runs command.png
  2. Just run generatorcode.

Problem description

If there are text or blob fields in the database table. The automatically generated database configuration files are as follows, with several more methods and resultmaps ending with blobs:

<!--Just paste different parts-->
<resultMap extends="BaseResultMap" id="ResultMapWithBLOBs" type="com.cx.elearnning.model.EduWebsiteProfile">
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    <result column="DESCIPTION" jdbcType="LONGVARCHAR" property="desciption" />

<select id="selectByExampleWithBLOBs" parameterType="com.cx.elearnning.model.EduWebsiteProfileExample" resultMap="ResultMapWithBLOBs">
      WARNING - @mbggenerated
      This element is automatically generated by MyBatis Generator, do not modify.
    <if test="distinct">
    <include refid="Base_Column_List" />
    <include refid="Blob_Column_List" />
    from edu_website_profile
    <if test="_parameter != null">
      <include refid="Example_Where_Clause" />
    <if test="orderByClause != null">
      order by ${orderByClause}

If selectByExample or updateByExample is still used to query or update data at this time, the resulting text or blob data is null.

Correct approach

You should use the two methods selectByExampleWithBLOBs or updateByExampleWithBLOBs.

Posted by matthew1 on Thu, 30 Apr 2020 05:27:55 -0700