mybatis-generator扩展教程系列 -- 自定义sql xml文件

简介:          今天抽空写一下生成器比较重要的环节,如何自定义mybatis生成器的sql xml文件,因为原生出来的格式不好看,命名也不符合我们日常使用习惯,很多冗余的sql节点,下面我直接直入主题演示代码了,还是老规矩使用之前教程延续下来的项目用例1.

         今天抽空写一下生成器比较重要的环节,如何自定义mybatis生成器的sql xml文件,因为原生出来的格式不好看,命名也不符合我们日常使用习惯,很多冗余的sql节点,下面我直接直入主题演示代码了,还是老规矩使用之前教程延续下来的项目用例


1.先看看我们原始生成出来的mapper.xml文件,1.节点间没有空行不符合我们日常格式 2.CRUD方法太累赘,我们其实只需要insert,update,delete,select

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.dao.QfdSketchMapper">
  <resultMap id="BaseResultMap" type="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="courseName" jdbcType="VARCHAR" property="coursename" />
    <result column="courseReq" jdbcType="VARCHAR" property="coursereq" />
    <result column="teaId" jdbcType="VARCHAR" property="teaid" />
    <result column="teaName" jdbcType="VARCHAR" property="teaname" />
    <result column="stuId" jdbcType="VARCHAR" property="stuid" />
    <result column="stuName" jdbcType="VARCHAR" property="stuname" />
    <result column="stuPhone" jdbcType="VARCHAR" property="stuphone" />
    <result column="textbookId" jdbcType="BIGINT" property="textbookid" />
    <result column="creator" jdbcType="VARCHAR" property="creator" />
    <result column="lastModifier" jdbcType="VARCHAR" property="lastmodifier" />
    <result column="countDate" jdbcType="INTEGER" property="countdate" />
    <result column="countTime" jdbcType="INTEGER" property="counttime" />
    <result column="countStu" jdbcType="INTEGER" property="countstu" />
    <result column="sketchType" jdbcType="INTEGER" property="sketchtype" />
    <result column="courseStyle" jdbcType="INTEGER" property="coursestyle" />
    <result column="classType" jdbcType="INTEGER" property="classtype" />
    <result column="process" jdbcType="INTEGER" property="process" />
    <result column="courseStatus" jdbcType="INTEGER" property="coursestatus" />
    <result column="pay" jdbcType="VARCHAR" property="pay" />
    <result column="perPay" jdbcType="VARCHAR" property="perpay" />
    <result column="couponPay" jdbcType="VARCHAR" property="couponpay" />
    <result column="originalPay" jdbcType="VARCHAR" property="originalpay" />
    <result column="couponRule" jdbcType="INTEGER" property="couponrule" />
    <result column="beginDate" jdbcType="BIGINT" property="begindate" />
    <result column="endDate" jdbcType="BIGINT" property="enddate" />
    <result column="courseNum" jdbcType="INTEGER" property="coursenum" />
    <result column="hasNum" jdbcType="INTEGER" property="hasnum" />
    <result column="cancelNum" jdbcType="INTEGER" property="cancelnum" />
    <result column="courseNumInput" jdbcType="INTEGER" property="coursenuminput" />
    <result column="orderNum" jdbcType="INTEGER" property="ordernum" />
    <result column="fav" jdbcType="BIGINT" property="fav" />
    <result column="vipLevel" jdbcType="INTEGER" property="viplevel" />
    <result column="cancelReason" jdbcType="INTEGER" property="cancelreason" />
    <result column="createDate" jdbcType="BIGINT" property="createdate" />
    <result column="lastModDate" jdbcType="BIGINT" property="lastmoddate" />
    <result column="formatter" jdbcType="VARCHAR" property="formatter" />
    <result column="status" jdbcType="TINYINT" property="status" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    id, courseName, courseReq, teaId, teaName, stuId, stuName, stuPhone, textbookId, 
    creator, lastModifier, countDate, countTime, countStu, sketchType, courseStyle, classType, 
    process, courseStatus, pay, perPay, couponPay, originalPay, couponRule, beginDate, 
    endDate, courseNum, hasNum, cancelNum, courseNumInput, orderNum, fav, vipLevel, cancelReason, 
    createDate, lastModDate, formatter, status
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Long" resultMap="BaseResultMap">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    select 
    <include refid="Base_Column_List" />
    from qfd_sketch
    where id = #{id,jdbcType=BIGINT}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from qfd_sketch
    where id = #{id,jdbcType=BIGINT}
  </delete>
  <insert id="insert" parameterType="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into qfd_sketch (id, courseName, courseReq, 
      teaId, teaName, stuId, 
      stuName, stuPhone, textbookId, 
      creator, lastModifier, countDate, 
      countTime, countStu, sketchType, 
      courseStyle, classType, process, 
      courseStatus, pay, perPay, 
      couponPay, originalPay, couponRule, 
      beginDate, endDate, courseNum, 
      hasNum, cancelNum, courseNumInput, 
      orderNum, fav, vipLevel, 
      cancelReason, createDate, lastModDate, 
      formatter, status)
    values (#{id,jdbcType=BIGINT}, #{coursename,jdbcType=VARCHAR}, #{coursereq,jdbcType=VARCHAR}, 
      #{teaid,jdbcType=VARCHAR}, #{teaname,jdbcType=VARCHAR}, #{stuid,jdbcType=VARCHAR}, 
      #{stuname,jdbcType=VARCHAR}, #{stuphone,jdbcType=VARCHAR}, #{textbookid,jdbcType=BIGINT}, 
      #{creator,jdbcType=VARCHAR}, #{lastmodifier,jdbcType=VARCHAR}, #{countdate,jdbcType=INTEGER}, 
      #{counttime,jdbcType=INTEGER}, #{countstu,jdbcType=INTEGER}, #{sketchtype,jdbcType=INTEGER}, 
      #{coursestyle,jdbcType=INTEGER}, #{classtype,jdbcType=INTEGER}, #{process,jdbcType=INTEGER}, 
      #{coursestatus,jdbcType=INTEGER}, #{pay,jdbcType=VARCHAR}, #{perpay,jdbcType=VARCHAR}, 
      #{couponpay,jdbcType=VARCHAR}, #{originalpay,jdbcType=VARCHAR}, #{couponrule,jdbcType=INTEGER}, 
      #{begindate,jdbcType=BIGINT}, #{enddate,jdbcType=BIGINT}, #{coursenum,jdbcType=INTEGER}, 
      #{hasnum,jdbcType=INTEGER}, #{cancelnum,jdbcType=INTEGER}, #{coursenuminput,jdbcType=INTEGER}, 
      #{ordernum,jdbcType=INTEGER}, #{fav,jdbcType=BIGINT}, #{viplevel,jdbcType=INTEGER}, 
      #{cancelreason,jdbcType=INTEGER}, #{createdate,jdbcType=BIGINT}, #{lastmoddate,jdbcType=BIGINT}, 
      #{formatter,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT})
  </insert>
  <insert id="insertSelective" parameterType="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into qfd_sketch
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="coursename != null">
        courseName,
      </if>
      <if test="coursereq != null">
        courseReq,
      </if>
      <if test="teaid != null">
        teaId,
      </if>
      <if test="teaname != null">
        teaName,
      </if>
      <if test="stuid != null">
        stuId,
      </if>
      <if test="stuname != null">
        stuName,
      </if>
      <if test="stuphone != null">
        stuPhone,
      </if>
      <if test="textbookid != null">
        textbookId,
      </if>
      <if test="creator != null">
        creator,
      </if>
      <if test="lastmodifier != null">
        lastModifier,
      </if>
      <if test="countdate != null">
        countDate,
      </if>
      <if test="counttime != null">
        countTime,
      </if>
      <if test="countstu != null">
        countStu,
      </if>
      <if test="sketchtype != null">
        sketchType,
      </if>
      <if test="coursestyle != null">
        courseStyle,
      </if>
      <if test="classtype != null">
        classType,
      </if>
      <if test="process != null">
        process,
      </if>
      <if test="coursestatus != null">
        courseStatus,
      </if>
      <if test="pay != null">
        pay,
      </if>
      <if test="perpay != null">
        perPay,
      </if>
      <if test="couponpay != null">
        couponPay,
      </if>
      <if test="originalpay != null">
        originalPay,
      </if>
      <if test="couponrule != null">
        couponRule,
      </if>
      <if test="begindate != null">
        beginDate,
      </if>
      <if test="enddate != null">
        endDate,
      </if>
      <if test="coursenum != null">
        courseNum,
      </if>
      <if test="hasnum != null">
        hasNum,
      </if>
      <if test="cancelnum != null">
        cancelNum,
      </if>
      <if test="coursenuminput != null">
        courseNumInput,
      </if>
      <if test="ordernum != null">
        orderNum,
      </if>
      <if test="fav != null">
        fav,
      </if>
      <if test="viplevel != null">
        vipLevel,
      </if>
      <if test="cancelreason != null">
        cancelReason,
      </if>
      <if test="createdate != null">
        createDate,
      </if>
      <if test="lastmoddate != null">
        lastModDate,
      </if>
      <if test="formatter != null">
        formatter,
      </if>
      <if test="status != null">
        status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="coursename != null">
        #{coursename,jdbcType=VARCHAR},
      </if>
      <if test="coursereq != null">
        #{coursereq,jdbcType=VARCHAR},
      </if>
      <if test="teaid != null">
        #{teaid,jdbcType=VARCHAR},
      </if>
      <if test="teaname != null">
        #{teaname,jdbcType=VARCHAR},
      </if>
      <if test="stuid != null">
        #{stuid,jdbcType=VARCHAR},
      </if>
      <if test="stuname != null">
        #{stuname,jdbcType=VARCHAR},
      </if>
      <if test="stuphone != null">
        #{stuphone,jdbcType=VARCHAR},
      </if>
      <if test="textbookid != null">
        #{textbookid,jdbcType=BIGINT},
      </if>
      <if test="creator != null">
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="lastmodifier != null">
        #{lastmodifier,jdbcType=VARCHAR},
      </if>
      <if test="countdate != null">
        #{countdate,jdbcType=INTEGER},
      </if>
      <if test="counttime != null">
        #{counttime,jdbcType=INTEGER},
      </if>
      <if test="countstu != null">
        #{countstu,jdbcType=INTEGER},
      </if>
      <if test="sketchtype != null">
        #{sketchtype,jdbcType=INTEGER},
      </if>
      <if test="coursestyle != null">
        #{coursestyle,jdbcType=INTEGER},
      </if>
      <if test="classtype != null">
        #{classtype,jdbcType=INTEGER},
      </if>
      <if test="process != null">
        #{process,jdbcType=INTEGER},
      </if>
      <if test="coursestatus != null">
        #{coursestatus,jdbcType=INTEGER},
      </if>
      <if test="pay != null">
        #{pay,jdbcType=VARCHAR},
      </if>
      <if test="perpay != null">
        #{perpay,jdbcType=VARCHAR},
      </if>
      <if test="couponpay != null">
        #{couponpay,jdbcType=VARCHAR},
      </if>
      <if test="originalpay != null">
        #{originalpay,jdbcType=VARCHAR},
      </if>
      <if test="couponrule != null">
        #{couponrule,jdbcType=INTEGER},
      </if>
      <if test="begindate != null">
        #{begindate,jdbcType=BIGINT},
      </if>
      <if test="enddate != null">
        #{enddate,jdbcType=BIGINT},
      </if>
      <if test="coursenum != null">
        #{coursenum,jdbcType=INTEGER},
      </if>
      <if test="hasnum != null">
        #{hasnum,jdbcType=INTEGER},
      </if>
      <if test="cancelnum != null">
        #{cancelnum,jdbcType=INTEGER},
      </if>
      <if test="coursenuminput != null">
        #{coursenuminput,jdbcType=INTEGER},
      </if>
      <if test="ordernum != null">
        #{ordernum,jdbcType=INTEGER},
      </if>
      <if test="fav != null">
        #{fav,jdbcType=BIGINT},
      </if>
      <if test="viplevel != null">
        #{viplevel,jdbcType=INTEGER},
      </if>
      <if test="cancelreason != null">
        #{cancelreason,jdbcType=INTEGER},
      </if>
      <if test="createdate != null">
        #{createdate,jdbcType=BIGINT},
      </if>
      <if test="lastmoddate != null">
        #{lastmoddate,jdbcType=BIGINT},
      </if>
      <if test="formatter != null">
        #{formatter,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update qfd_sketch
    <set>
      <if test="coursename != null">
        courseName = #{coursename,jdbcType=VARCHAR},
      </if>
      <if test="coursereq != null">
        courseReq = #{coursereq,jdbcType=VARCHAR},
      </if>
      <if test="teaid != null">
        teaId = #{teaid,jdbcType=VARCHAR},
      </if>
      <if test="teaname != null">
        teaName = #{teaname,jdbcType=VARCHAR},
      </if>
      <if test="stuid != null">
        stuId = #{stuid,jdbcType=VARCHAR},
      </if>
      <if test="stuname != null">
        stuName = #{stuname,jdbcType=VARCHAR},
      </if>
      <if test="stuphone != null">
        stuPhone = #{stuphone,jdbcType=VARCHAR},
      </if>
      <if test="textbookid != null">
        textbookId = #{textbookid,jdbcType=BIGINT},
      </if>
      <if test="creator != null">
        creator = #{creator,jdbcType=VARCHAR},
      </if>
      <if test="lastmodifier != null">
        lastModifier = #{lastmodifier,jdbcType=VARCHAR},
      </if>
      <if test="countdate != null">
        countDate = #{countdate,jdbcType=INTEGER},
      </if>
      <if test="counttime != null">
        countTime = #{counttime,jdbcType=INTEGER},
      </if>
      <if test="countstu != null">
        countStu = #{countstu,jdbcType=INTEGER},
      </if>
      <if test="sketchtype != null">
        sketchType = #{sketchtype,jdbcType=INTEGER},
      </if>
      <if test="coursestyle != null">
        courseStyle = #{coursestyle,jdbcType=INTEGER},
      </if>
      <if test="classtype != null">
        classType = #{classtype,jdbcType=INTEGER},
      </if>
      <if test="process != null">
        process = #{process,jdbcType=INTEGER},
      </if>
      <if test="coursestatus != null">
        courseStatus = #{coursestatus,jdbcType=INTEGER},
      </if>
      <if test="pay != null">
        pay = #{pay,jdbcType=VARCHAR},
      </if>
      <if test="perpay != null">
        perPay = #{perpay,jdbcType=VARCHAR},
      </if>
      <if test="couponpay != null">
        couponPay = #{couponpay,jdbcType=VARCHAR},
      </if>
      <if test="originalpay != null">
        originalPay = #{originalpay,jdbcType=VARCHAR},
      </if>
      <if test="couponrule != null">
        couponRule = #{couponrule,jdbcType=INTEGER},
      </if>
      <if test="begindate != null">
        beginDate = #{begindate,jdbcType=BIGINT},
      </if>
      <if test="enddate != null">
        endDate = #{enddate,jdbcType=BIGINT},
      </if>
      <if test="coursenum != null">
        courseNum = #{coursenum,jdbcType=INTEGER},
      </if>
      <if test="hasnum != null">
        hasNum = #{hasnum,jdbcType=INTEGER},
      </if>
      <if test="cancelnum != null">
        cancelNum = #{cancelnum,jdbcType=INTEGER},
      </if>
      <if test="coursenuminput != null">
        courseNumInput = #{coursenuminput,jdbcType=INTEGER},
      </if>
      <if test="ordernum != null">
        orderNum = #{ordernum,jdbcType=INTEGER},
      </if>
      <if test="fav != null">
        fav = #{fav,jdbcType=BIGINT},
      </if>
      <if test="viplevel != null">
        vipLevel = #{viplevel,jdbcType=INTEGER},
      </if>
      <if test="cancelreason != null">
        cancelReason = #{cancelreason,jdbcType=INTEGER},
      </if>
      <if test="createdate != null">
        createDate = #{createdate,jdbcType=BIGINT},
      </if>
      <if test="lastmoddate != null">
        lastModDate = #{lastmoddate,jdbcType=BIGINT},
      </if>
      <if test="formatter != null">
        formatter = #{formatter,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=TINYINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update qfd_sketch
    set courseName = #{coursename,jdbcType=VARCHAR},
      courseReq = #{coursereq,jdbcType=VARCHAR},
      teaId = #{teaid,jdbcType=VARCHAR},
      teaName = #{teaname,jdbcType=VARCHAR},
      stuId = #{stuid,jdbcType=VARCHAR},
      stuName = #{stuname,jdbcType=VARCHAR},
      stuPhone = #{stuphone,jdbcType=VARCHAR},
      textbookId = #{textbookid,jdbcType=BIGINT},
      creator = #{creator,jdbcType=VARCHAR},
      lastModifier = #{lastmodifier,jdbcType=VARCHAR},
      countDate = #{countdate,jdbcType=INTEGER},
      countTime = #{counttime,jdbcType=INTEGER},
      countStu = #{countstu,jdbcType=INTEGER},
      sketchType = #{sketchtype,jdbcType=INTEGER},
      courseStyle = #{coursestyle,jdbcType=INTEGER},
      classType = #{classtype,jdbcType=INTEGER},
      process = #{process,jdbcType=INTEGER},
      courseStatus = #{coursestatus,jdbcType=INTEGER},
      pay = #{pay,jdbcType=VARCHAR},
      perPay = #{perpay,jdbcType=VARCHAR},
      couponPay = #{couponpay,jdbcType=VARCHAR},
      originalPay = #{originalpay,jdbcType=VARCHAR},
      couponRule = #{couponrule,jdbcType=INTEGER},
      beginDate = #{begindate,jdbcType=BIGINT},
      endDate = #{enddate,jdbcType=BIGINT},
      courseNum = #{coursenum,jdbcType=INTEGER},
      hasNum = #{hasnum,jdbcType=INTEGER},
      cancelNum = #{cancelnum,jdbcType=INTEGER},
      courseNumInput = #{coursenuminput,jdbcType=INTEGER},
      orderNum = #{ordernum,jdbcType=INTEGER},
      fav = #{fav,jdbcType=BIGINT},
      vipLevel = #{viplevel,jdbcType=INTEGER},
      cancelReason = #{cancelreason,jdbcType=INTEGER},
      createDate = #{createdate,jdbcType=BIGINT},
      lastModDate = #{lastmoddate,jdbcType=BIGINT},
      formatter = #{formatter,jdbcType=VARCHAR},
      status = #{status,jdbcType=TINYINT}
    where id = #{id,jdbcType=BIGINT}
  </update>
</mapper>

2.根据已知问题,我们先处理一下问题吧,保留insert,update,delete方法作为示例,顺便给他们增加隔行的格式化

先看看XMLMapperGenerator.java这个类的getSqlMapElement()方法,可以看到很多addxxx方法,这里就是拼接sql xml文件的逻辑,我们只保留必须的方法

protected XmlElement getSqlMapElement() {
        FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
        progressCallback.startTask(getString(
                "Progress.12", table.toString())); //$NON-NLS-1$
        XmlElement answer = new XmlElement("mapper"); //$NON-NLS-1$
        String namespace = introspectedTable.getMyBatis3SqlMapNamespace();
        answer.addAttribute(new Attribute("namespace", //$NON-NLS-1$
                namespace));

        context.getCommentGenerator().addRootComment(answer);

        addResultMapWithoutBLOBsElement(answer);
        addResultMapWithBLOBsElement(answer);
        addExampleWhereClauseElement(answer);
        addMyBatis3UpdateByExampleWhereClauseElement(answer);
        addBaseColumnListElement(answer);
        addBlobColumnListElement(answer);
        addSelectByExampleWithBLOBsElement(answer);
        addSelectByExampleWithoutBLOBsElement(answer);
        addSelectByPrimaryKeyElement(answer);
        addDeleteByPrimaryKeyElement(answer);
        addDeleteByExampleElement(answer);
        addInsertElement(answer);
        addInsertSelectiveElement(answer);
        addCountByExampleElement(answer);
        addUpdateByExampleSelectiveElement(answer);
        addUpdateByExampleWithBLOBsElement(answer);
        addUpdateByExampleWithoutBLOBsElement(answer);
        addUpdateByPrimaryKeySelectiveElement(answer);
        addUpdateByPrimaryKeyWithBLOBsElement(answer);
        addUpdateByPrimaryKeyWithoutBLOBsElement(answer);
        
        return answer;
    }

修改后的方法

protected XmlElement getSqlMapElement() {
        FullyQualifiedTable table = introspectedTable.getFullyQualifiedTable();
        progressCallback.startTask(getString(
                "Progress.12", table.toString())); //$NON-NLS-1$
        XmlElement answer = new XmlElement("mapper"); //$NON-NLS-1$
        String namespace = introspectedTable.getMyBatis3SqlMapNamespace();
        answer.addAttribute(new Attribute("namespace", //$NON-NLS-1$
                namespace));

        context.getCommentGenerator().addRootComment(answer);

//        addResultMapWithoutBLOBsElement(answer);
//        addResultMapWithBLOBsElement(answer);
//        addExampleWhereClauseElement(answer);
//        addMyBatis3UpdateByExampleWhereClauseElement(answer);
//        addBaseColumnListElement(answer);
//        addBlobColumnListElement(answer);
//        addSelectByExampleWithBLOBsElement(answer);
//        addSelectByExampleWithoutBLOBsElement(answer);
//        addSelectByPrimaryKeyElement(answer);
//        addDeleteByPrimaryKeyElement(answer);
//        addDeleteByExampleElement(answer);
//        addInsertElement(answer);
//        addInsertSelectiveElement(answer);
//        addCountByExampleElement(answer);
//        addUpdateByExampleSelectiveElement(answer);
//        addUpdateByExampleWithBLOBsElement(answer);
//        addUpdateByExampleWithoutBLOBsElement(answer);
//        addUpdateByPrimaryKeySelectiveElement(answer);
//        addUpdateByPrimaryKeyWithBLOBsElement(answer);
//        addUpdateByPrimaryKeyWithoutBLOBsElement(answer);
        
        addResultMapWithoutBLOBsElement(answer);
        addBaseColumnListElement(answer);
        addInsertSelectiveElement(answer);
        addUpdateByPrimaryKeySelectiveElement(answer);
        addDeleteByPrimaryKeyElement(answer);

        return answer;
    }

3.修改这个方法后,我们运行下生成文件看看效果

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.dao.QfdSketchMapper">
  <resultMap id="BaseResultMap" type="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    <id column="id" jdbcType="BIGINT" property="id" />
    <result column="courseName" jdbcType="VARCHAR" property="coursename" />
    <result column="courseReq" jdbcType="VARCHAR" property="coursereq" />
    <result column="teaId" jdbcType="VARCHAR" property="teaid" />
    <result column="teaName" jdbcType="VARCHAR" property="teaname" />
    <result column="stuId" jdbcType="VARCHAR" property="stuid" />
    <result column="stuName" jdbcType="VARCHAR" property="stuname" />
    <result column="stuPhone" jdbcType="VARCHAR" property="stuphone" />
    <result column="textbookId" jdbcType="BIGINT" property="textbookid" />
    <result column="creator" jdbcType="VARCHAR" property="creator" />
    <result column="lastModifier" jdbcType="VARCHAR" property="lastmodifier" />
    <result column="countDate" jdbcType="INTEGER" property="countdate" />
    <result column="countTime" jdbcType="INTEGER" property="counttime" />
    <result column="countStu" jdbcType="INTEGER" property="countstu" />
    <result column="sketchType" jdbcType="INTEGER" property="sketchtype" />
    <result column="courseStyle" jdbcType="INTEGER" property="coursestyle" />
    <result column="classType" jdbcType="INTEGER" property="classtype" />
    <result column="process" jdbcType="INTEGER" property="process" />
    <result column="courseStatus" jdbcType="INTEGER" property="coursestatus" />
    <result column="pay" jdbcType="VARCHAR" property="pay" />
    <result column="perPay" jdbcType="VARCHAR" property="perpay" />
    <result column="couponPay" jdbcType="VARCHAR" property="couponpay" />
    <result column="originalPay" jdbcType="VARCHAR" property="originalpay" />
    <result column="couponRule" jdbcType="INTEGER" property="couponrule" />
    <result column="beginDate" jdbcType="BIGINT" property="begindate" />
    <result column="endDate" jdbcType="BIGINT" property="enddate" />
    <result column="courseNum" jdbcType="INTEGER" property="coursenum" />
    <result column="hasNum" jdbcType="INTEGER" property="hasnum" />
    <result column="cancelNum" jdbcType="INTEGER" property="cancelnum" />
    <result column="courseNumInput" jdbcType="INTEGER" property="coursenuminput" />
    <result column="orderNum" jdbcType="INTEGER" property="ordernum" />
    <result column="fav" jdbcType="BIGINT" property="fav" />
    <result column="vipLevel" jdbcType="INTEGER" property="viplevel" />
    <result column="cancelReason" jdbcType="INTEGER" property="cancelreason" />
    <result column="createDate" jdbcType="BIGINT" property="createdate" />
    <result column="lastModDate" jdbcType="BIGINT" property="lastmoddate" />
    <result column="formatter" jdbcType="VARCHAR" property="formatter" />
    <result column="status" jdbcType="TINYINT" property="status" />
  </resultMap>
  <sql id="Base_Column_List">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    id, courseName, courseReq, teaId, teaName, stuId, stuName, stuPhone, textbookId, 
    creator, lastModifier, countDate, countTime, countStu, sketchType, courseStyle, classType, 
    process, courseStatus, pay, perPay, couponPay, originalPay, couponRule, beginDate, 
    endDate, courseNum, hasNum, cancelNum, courseNumInput, orderNum, fav, vipLevel, cancelReason, 
    createDate, lastModDate, formatter, status
  </sql>
  <insert id="insertSelective" parameterType="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    insert into qfd_sketch
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="id != null">
        id,
      </if>
      <if test="coursename != null">
        courseName,
      </if>
      <if test="coursereq != null">
        courseReq,
      </if>
      <if test="teaid != null">
        teaId,
      </if>
      <if test="teaname != null">
        teaName,
      </if>
      <if test="stuid != null">
        stuId,
      </if>
      <if test="stuname != null">
        stuName,
      </if>
      <if test="stuphone != null">
        stuPhone,
      </if>
      <if test="textbookid != null">
        textbookId,
      </if>
      <if test="creator != null">
        creator,
      </if>
      <if test="lastmodifier != null">
        lastModifier,
      </if>
      <if test="countdate != null">
        countDate,
      </if>
      <if test="counttime != null">
        countTime,
      </if>
      <if test="countstu != null">
        countStu,
      </if>
      <if test="sketchtype != null">
        sketchType,
      </if>
      <if test="coursestyle != null">
        courseStyle,
      </if>
      <if test="classtype != null">
        classType,
      </if>
      <if test="process != null">
        process,
      </if>
      <if test="coursestatus != null">
        courseStatus,
      </if>
      <if test="pay != null">
        pay,
      </if>
      <if test="perpay != null">
        perPay,
      </if>
      <if test="couponpay != null">
        couponPay,
      </if>
      <if test="originalpay != null">
        originalPay,
      </if>
      <if test="couponrule != null">
        couponRule,
      </if>
      <if test="begindate != null">
        beginDate,
      </if>
      <if test="enddate != null">
        endDate,
      </if>
      <if test="coursenum != null">
        courseNum,
      </if>
      <if test="hasnum != null">
        hasNum,
      </if>
      <if test="cancelnum != null">
        cancelNum,
      </if>
      <if test="coursenuminput != null">
        courseNumInput,
      </if>
      <if test="ordernum != null">
        orderNum,
      </if>
      <if test="fav != null">
        fav,
      </if>
      <if test="viplevel != null">
        vipLevel,
      </if>
      <if test="cancelreason != null">
        cancelReason,
      </if>
      <if test="createdate != null">
        createDate,
      </if>
      <if test="lastmoddate != null">
        lastModDate,
      </if>
      <if test="formatter != null">
        formatter,
      </if>
      <if test="status != null">
        status,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="id != null">
        #{id,jdbcType=BIGINT},
      </if>
      <if test="coursename != null">
        #{coursename,jdbcType=VARCHAR},
      </if>
      <if test="coursereq != null">
        #{coursereq,jdbcType=VARCHAR},
      </if>
      <if test="teaid != null">
        #{teaid,jdbcType=VARCHAR},
      </if>
      <if test="teaname != null">
        #{teaname,jdbcType=VARCHAR},
      </if>
      <if test="stuid != null">
        #{stuid,jdbcType=VARCHAR},
      </if>
      <if test="stuname != null">
        #{stuname,jdbcType=VARCHAR},
      </if>
      <if test="stuphone != null">
        #{stuphone,jdbcType=VARCHAR},
      </if>
      <if test="textbookid != null">
        #{textbookid,jdbcType=BIGINT},
      </if>
      <if test="creator != null">
        #{creator,jdbcType=VARCHAR},
      </if>
      <if test="lastmodifier != null">
        #{lastmodifier,jdbcType=VARCHAR},
      </if>
      <if test="countdate != null">
        #{countdate,jdbcType=INTEGER},
      </if>
      <if test="counttime != null">
        #{counttime,jdbcType=INTEGER},
      </if>
      <if test="countstu != null">
        #{countstu,jdbcType=INTEGER},
      </if>
      <if test="sketchtype != null">
        #{sketchtype,jdbcType=INTEGER},
      </if>
      <if test="coursestyle != null">
        #{coursestyle,jdbcType=INTEGER},
      </if>
      <if test="classtype != null">
        #{classtype,jdbcType=INTEGER},
      </if>
      <if test="process != null">
        #{process,jdbcType=INTEGER},
      </if>
      <if test="coursestatus != null">
        #{coursestatus,jdbcType=INTEGER},
      </if>
      <if test="pay != null">
        #{pay,jdbcType=VARCHAR},
      </if>
      <if test="perpay != null">
        #{perpay,jdbcType=VARCHAR},
      </if>
      <if test="couponpay != null">
        #{couponpay,jdbcType=VARCHAR},
      </if>
      <if test="originalpay != null">
        #{originalpay,jdbcType=VARCHAR},
      </if>
      <if test="couponrule != null">
        #{couponrule,jdbcType=INTEGER},
      </if>
      <if test="begindate != null">
        #{begindate,jdbcType=BIGINT},
      </if>
      <if test="enddate != null">
        #{enddate,jdbcType=BIGINT},
      </if>
      <if test="coursenum != null">
        #{coursenum,jdbcType=INTEGER},
      </if>
      <if test="hasnum != null">
        #{hasnum,jdbcType=INTEGER},
      </if>
      <if test="cancelnum != null">
        #{cancelnum,jdbcType=INTEGER},
      </if>
      <if test="coursenuminput != null">
        #{coursenuminput,jdbcType=INTEGER},
      </if>
      <if test="ordernum != null">
        #{ordernum,jdbcType=INTEGER},
      </if>
      <if test="fav != null">
        #{fav,jdbcType=BIGINT},
      </if>
      <if test="viplevel != null">
        #{viplevel,jdbcType=INTEGER},
      </if>
      <if test="cancelreason != null">
        #{cancelreason,jdbcType=INTEGER},
      </if>
      <if test="createdate != null">
        #{createdate,jdbcType=BIGINT},
      </if>
      <if test="lastmoddate != null">
        #{lastmoddate,jdbcType=BIGINT},
      </if>
      <if test="formatter != null">
        #{formatter,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        #{status,jdbcType=TINYINT},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="com.test.domain.QfdSketch">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    update qfd_sketch
    <set>
      <if test="coursename != null">
        courseName = #{coursename,jdbcType=VARCHAR},
      </if>
      <if test="coursereq != null">
        courseReq = #{coursereq,jdbcType=VARCHAR},
      </if>
      <if test="teaid != null">
        teaId = #{teaid,jdbcType=VARCHAR},
      </if>
      <if test="teaname != null">
        teaName = #{teaname,jdbcType=VARCHAR},
      </if>
      <if test="stuid != null">
        stuId = #{stuid,jdbcType=VARCHAR},
      </if>
      <if test="stuname != null">
        stuName = #{stuname,jdbcType=VARCHAR},
      </if>
      <if test="stuphone != null">
        stuPhone = #{stuphone,jdbcType=VARCHAR},
      </if>
      <if test="textbookid != null">
        textbookId = #{textbookid,jdbcType=BIGINT},
      </if>
      <if test="creator != null">
        creator = #{creator,jdbcType=VARCHAR},
      </if>
      <if test="lastmodifier != null">
        lastModifier = #{lastmodifier,jdbcType=VARCHAR},
      </if>
      <if test="countdate != null">
        countDate = #{countdate,jdbcType=INTEGER},
      </if>
      <if test="counttime != null">
        countTime = #{counttime,jdbcType=INTEGER},
      </if>
      <if test="countstu != null">
        countStu = #{countstu,jdbcType=INTEGER},
      </if>
      <if test="sketchtype != null">
        sketchType = #{sketchtype,jdbcType=INTEGER},
      </if>
      <if test="coursestyle != null">
        courseStyle = #{coursestyle,jdbcType=INTEGER},
      </if>
      <if test="classtype != null">
        classType = #{classtype,jdbcType=INTEGER},
      </if>
      <if test="process != null">
        process = #{process,jdbcType=INTEGER},
      </if>
      <if test="coursestatus != null">
        courseStatus = #{coursestatus,jdbcType=INTEGER},
      </if>
      <if test="pay != null">
        pay = #{pay,jdbcType=VARCHAR},
      </if>
      <if test="perpay != null">
        perPay = #{perpay,jdbcType=VARCHAR},
      </if>
      <if test="couponpay != null">
        couponPay = #{couponpay,jdbcType=VARCHAR},
      </if>
      <if test="originalpay != null">
        originalPay = #{originalpay,jdbcType=VARCHAR},
      </if>
      <if test="couponrule != null">
        couponRule = #{couponrule,jdbcType=INTEGER},
      </if>
      <if test="begindate != null">
        beginDate = #{begindate,jdbcType=BIGINT},
      </if>
      <if test="enddate != null">
        endDate = #{enddate,jdbcType=BIGINT},
      </if>
      <if test="coursenum != null">
        courseNum = #{coursenum,jdbcType=INTEGER},
      </if>
      <if test="hasnum != null">
        hasNum = #{hasnum,jdbcType=INTEGER},
      </if>
      <if test="cancelnum != null">
        cancelNum = #{cancelnum,jdbcType=INTEGER},
      </if>
      <if test="coursenuminput != null">
        courseNumInput = #{coursenuminput,jdbcType=INTEGER},
      </if>
      <if test="ordernum != null">
        orderNum = #{ordernum,jdbcType=INTEGER},
      </if>
      <if test="fav != null">
        fav = #{fav,jdbcType=BIGINT},
      </if>
      <if test="viplevel != null">
        vipLevel = #{viplevel,jdbcType=INTEGER},
      </if>
      <if test="cancelreason != null">
        cancelReason = #{cancelreason,jdbcType=INTEGER},
      </if>
      <if test="createdate != null">
        createDate = #{createdate,jdbcType=BIGINT},
      </if>
      <if test="lastmoddate != null">
        lastModDate = #{lastmoddate,jdbcType=BIGINT},
      </if>
      <if test="formatter != null">
        formatter = #{formatter,jdbcType=VARCHAR},
      </if>
      <if test="status != null">
        status = #{status,jdbcType=TINYINT},
      </if>
    </set>
    where id = #{id,jdbcType=BIGINT}
  </update>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
    <!--
      WARNING - @mbg.generated
      This element is automatically generated by MyBatis Generator, do not modify.
    -->
    delete from qfd_sketch
    where id = #{id,jdbcType=BIGINT}
  </delete>
</mapper>


4.看到上面的文件后发现已经达到我们一个目的了,把多余的方法给去掉,但是格式不够好看,我们来完成下面一个目标,增加sql节点隔行以及修改sql语句缩进格式

继续看XMLMapperGenerator.java类的initializeAndExecuteGenerator()方法

protected void initializeAndExecuteGenerator(
            AbstractXmlElementGenerator elementGenerator,
            XmlElement parentElement) {
        elementGenerator.setContext(context);
        elementGenerator.setIntrospectedTable(introspectedTable);
        elementGenerator.setProgressCallback(progressCallback);
        elementGenerator.setWarnings(warnings);
        elementGenerator.addElements(parentElement);
    }

修改后的方法

protected void initializeAndExecuteGenerator(
            AbstractXmlElementGenerator elementGenerator,
            XmlElement parentElement) {
        elementGenerator.setContext(context);
        elementGenerator.setIntrospectedTable(introspectedTable);
        elementGenerator.setProgressCallback(progressCallback);
        elementGenerator.setWarnings(warnings);
        parentElement.addElement(new TextElement("")); // 增加一行空白的隔行
        elementGenerator.addElements(parentElement);
    }


打开OutputUtilities.java方法看

public static void xmlIndent(StringBuilder sb, int indentLevel) {
        for (int i = 0; i < indentLevel; i++) {
            sb.append("  "); //$NON-NLS-1$
        }
    }

把两个空格符变成4个空格符

public static void xmlIndent(StringBuilder sb, int indentLevel) {
        for (int i = 0; i < indentLevel; i++) {
        	// sb.append("  "); //$NON-NLS-1$
        	sb.append("    "); // 4个空格符
        }
    }


5.修改方法后我们重新生成下xml文件看看效果

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.dao.QfdSketchMapper">
    
    <resultMap id="BaseResultMap" type="com.test.domain.QfdSketch">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="courseName" jdbcType="VARCHAR" property="coursename" />
        <result column="courseReq" jdbcType="VARCHAR" property="coursereq" />
        <result column="teaId" jdbcType="VARCHAR" property="teaid" />
        <result column="teaName" jdbcType="VARCHAR" property="teaname" />
        <result column="stuId" jdbcType="VARCHAR" property="stuid" />
        <result column="stuName" jdbcType="VARCHAR" property="stuname" />
        <result column="stuPhone" jdbcType="VARCHAR" property="stuphone" />
        <result column="textbookId" jdbcType="BIGINT" property="textbookid" />
        <result column="creator" jdbcType="VARCHAR" property="creator" />
        <result column="lastModifier" jdbcType="VARCHAR" property="lastmodifier" />
        <result column="countDate" jdbcType="INTEGER" property="countdate" />
        <result column="countTime" jdbcType="INTEGER" property="counttime" />
        <result column="countStu" jdbcType="INTEGER" property="countstu" />
        <result column="sketchType" jdbcType="INTEGER" property="sketchtype" />
        <result column="courseStyle" jdbcType="INTEGER" property="coursestyle" />
        <result column="classType" jdbcType="INTEGER" property="classtype" />
        <result column="process" jdbcType="INTEGER" property="process" />
        <result column="courseStatus" jdbcType="INTEGER" property="coursestatus" />
        <result column="pay" jdbcType="VARCHAR" property="pay" />
        <result column="perPay" jdbcType="VARCHAR" property="perpay" />
        <result column="couponPay" jdbcType="VARCHAR" property="couponpay" />
        <result column="originalPay" jdbcType="VARCHAR" property="originalpay" />
        <result column="couponRule" jdbcType="INTEGER" property="couponrule" />
        <result column="beginDate" jdbcType="BIGINT" property="begindate" />
        <result column="endDate" jdbcType="BIGINT" property="enddate" />
        <result column="courseNum" jdbcType="INTEGER" property="coursenum" />
        <result column="hasNum" jdbcType="INTEGER" property="hasnum" />
        <result column="cancelNum" jdbcType="INTEGER" property="cancelnum" />
        <result column="courseNumInput" jdbcType="INTEGER" property="coursenuminput" />
        <result column="orderNum" jdbcType="INTEGER" property="ordernum" />
        <result column="fav" jdbcType="BIGINT" property="fav" />
        <result column="vipLevel" jdbcType="INTEGER" property="viplevel" />
        <result column="cancelReason" jdbcType="INTEGER" property="cancelreason" />
        <result column="createDate" jdbcType="BIGINT" property="createdate" />
        <result column="lastModDate" jdbcType="BIGINT" property="lastmoddate" />
        <result column="formatter" jdbcType="VARCHAR" property="formatter" />
        <result column="status" jdbcType="TINYINT" property="status" />
    </resultMap>
    
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        id, courseName, courseReq, teaId, teaName, stuId, stuName, stuPhone, textbookId, 
        creator, lastModifier, countDate, countTime, countStu, sketchType, courseStyle, classType, 
        process, courseStatus, pay, perPay, couponPay, originalPay, couponRule, beginDate, 
        endDate, courseNum, hasNum, cancelNum, courseNumInput, orderNum, fav, vipLevel, cancelReason, 
        createDate, lastModDate, formatter, status
    </sql>
    
    <insert id="insertSelective" parameterType="com.test.domain.QfdSketch">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into qfd_sketch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="coursename != null">
                courseName,
            </if>
            <if test="coursereq != null">
                courseReq,
            </if>
            <if test="teaid != null">
                teaId,
            </if>
            <if test="teaname != null">
                teaName,
            </if>
            <if test="stuid != null">
                stuId,
            </if>
            <if test="stuname != null">
                stuName,
            </if>
            <if test="stuphone != null">
                stuPhone,
            </if>
            <if test="textbookid != null">
                textbookId,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="lastmodifier != null">
                lastModifier,
            </if>
            <if test="countdate != null">
                countDate,
            </if>
            <if test="counttime != null">
                countTime,
            </if>
            <if test="countstu != null">
                countStu,
            </if>
            <if test="sketchtype != null">
                sketchType,
            </if>
            <if test="coursestyle != null">
                courseStyle,
            </if>
            <if test="classtype != null">
                classType,
            </if>
            <if test="process != null">
                process,
            </if>
            <if test="coursestatus != null">
                courseStatus,
            </if>
            <if test="pay != null">
                pay,
            </if>
            <if test="perpay != null">
                perPay,
            </if>
            <if test="couponpay != null">
                couponPay,
            </if>
            <if test="originalpay != null">
                originalPay,
            </if>
            <if test="couponrule != null">
                couponRule,
            </if>
            <if test="begindate != null">
                beginDate,
            </if>
            <if test="enddate != null">
                endDate,
            </if>
            <if test="coursenum != null">
                courseNum,
            </if>
            <if test="hasnum != null">
                hasNum,
            </if>
            <if test="cancelnum != null">
                cancelNum,
            </if>
            <if test="coursenuminput != null">
                courseNumInput,
            </if>
            <if test="ordernum != null">
                orderNum,
            </if>
            <if test="fav != null">
                fav,
            </if>
            <if test="viplevel != null">
                vipLevel,
            </if>
            <if test="cancelreason != null">
                cancelReason,
            </if>
            <if test="createdate != null">
                createDate,
            </if>
            <if test="lastmoddate != null">
                lastModDate,
            </if>
            <if test="formatter != null">
                formatter,
            </if>
            <if test="status != null">
                status,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="coursename != null">
                #{coursename,jdbcType=VARCHAR},
            </if>
            <if test="coursereq != null">
                #{coursereq,jdbcType=VARCHAR},
            </if>
            <if test="teaid != null">
                #{teaid,jdbcType=VARCHAR},
            </if>
            <if test="teaname != null">
                #{teaname,jdbcType=VARCHAR},
            </if>
            <if test="stuid != null">
                #{stuid,jdbcType=VARCHAR},
            </if>
            <if test="stuname != null">
                #{stuname,jdbcType=VARCHAR},
            </if>
            <if test="stuphone != null">
                #{stuphone,jdbcType=VARCHAR},
            </if>
            <if test="textbookid != null">
                #{textbookid,jdbcType=BIGINT},
            </if>
            <if test="creator != null">
                #{creator,jdbcType=VARCHAR},
            </if>
            <if test="lastmodifier != null">
                #{lastmodifier,jdbcType=VARCHAR},
            </if>
            <if test="countdate != null">
                #{countdate,jdbcType=INTEGER},
            </if>
            <if test="counttime != null">
                #{counttime,jdbcType=INTEGER},
            </if>
            <if test="countstu != null">
                #{countstu,jdbcType=INTEGER},
            </if>
            <if test="sketchtype != null">
                #{sketchtype,jdbcType=INTEGER},
            </if>
            <if test="coursestyle != null">
                #{coursestyle,jdbcType=INTEGER},
            </if>
            <if test="classtype != null">
                #{classtype,jdbcType=INTEGER},
            </if>
            <if test="process != null">
                #{process,jdbcType=INTEGER},
            </if>
            <if test="coursestatus != null">
                #{coursestatus,jdbcType=INTEGER},
            </if>
            <if test="pay != null">
                #{pay,jdbcType=VARCHAR},
            </if>
            <if test="perpay != null">
                #{perpay,jdbcType=VARCHAR},
            </if>
            <if test="couponpay != null">
                #{couponpay,jdbcType=VARCHAR},
            </if>
            <if test="originalpay != null">
                #{originalpay,jdbcType=VARCHAR},
            </if>
            <if test="couponrule != null">
                #{couponrule,jdbcType=INTEGER},
            </if>
            <if test="begindate != null">
                #{begindate,jdbcType=BIGINT},
            </if>
            <if test="enddate != null">
                #{enddate,jdbcType=BIGINT},
            </if>
            <if test="coursenum != null">
                #{coursenum,jdbcType=INTEGER},
            </if>
            <if test="hasnum != null">
                #{hasnum,jdbcType=INTEGER},
            </if>
            <if test="cancelnum != null">
                #{cancelnum,jdbcType=INTEGER},
            </if>
            <if test="coursenuminput != null">
                #{coursenuminput,jdbcType=INTEGER},
            </if>
            <if test="ordernum != null">
                #{ordernum,jdbcType=INTEGER},
            </if>
            <if test="fav != null">
                #{fav,jdbcType=BIGINT},
            </if>
            <if test="viplevel != null">
                #{viplevel,jdbcType=INTEGER},
            </if>
            <if test="cancelreason != null">
                #{cancelreason,jdbcType=INTEGER},
            </if>
            <if test="createdate != null">
                #{createdate,jdbcType=BIGINT},
            </if>
            <if test="lastmoddate != null">
                #{lastmoddate,jdbcType=BIGINT},
            </if>
            <if test="formatter != null">
                #{formatter,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=TINYINT},
            </if>
        </trim>
    </insert>
    
    <update id="updateByPrimaryKeySelective" parameterType="com.test.domain.QfdSketch">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update qfd_sketch
        <set>
            <if test="coursename != null">
                courseName = #{coursename,jdbcType=VARCHAR},
            </if>
            <if test="coursereq != null">
                courseReq = #{coursereq,jdbcType=VARCHAR},
            </if>
            <if test="teaid != null">
                teaId = #{teaid,jdbcType=VARCHAR},
            </if>
            <if test="teaname != null">
                teaName = #{teaname,jdbcType=VARCHAR},
            </if>
            <if test="stuid != null">
                stuId = #{stuid,jdbcType=VARCHAR},
            </if>
            <if test="stuname != null">
                stuName = #{stuname,jdbcType=VARCHAR},
            </if>
            <if test="stuphone != null">
                stuPhone = #{stuphone,jdbcType=VARCHAR},
            </if>
            <if test="textbookid != null">
                textbookId = #{textbookid,jdbcType=BIGINT},
            </if>
            <if test="creator != null">
                creator = #{creator,jdbcType=VARCHAR},
            </if>
            <if test="lastmodifier != null">
                lastModifier = #{lastmodifier,jdbcType=VARCHAR},
            </if>
            <if test="countdate != null">
                countDate = #{countdate,jdbcType=INTEGER},
            </if>
            <if test="counttime != null">
                countTime = #{counttime,jdbcType=INTEGER},
            </if>
            <if test="countstu != null">
                countStu = #{countstu,jdbcType=INTEGER},
            </if>
            <if test="sketchtype != null">
                sketchType = #{sketchtype,jdbcType=INTEGER},
            </if>
            <if test="coursestyle != null">
                courseStyle = #{coursestyle,jdbcType=INTEGER},
            </if>
            <if test="classtype != null">
                classType = #{classtype,jdbcType=INTEGER},
            </if>
            <if test="process != null">
                process = #{process,jdbcType=INTEGER},
            </if>
            <if test="coursestatus != null">
                courseStatus = #{coursestatus,jdbcType=INTEGER},
            </if>
            <if test="pay != null">
                pay = #{pay,jdbcType=VARCHAR},
            </if>
            <if test="perpay != null">
                perPay = #{perpay,jdbcType=VARCHAR},
            </if>
            <if test="couponpay != null">
                couponPay = #{couponpay,jdbcType=VARCHAR},
            </if>
            <if test="originalpay != null">
                originalPay = #{originalpay,jdbcType=VARCHAR},
            </if>
            <if test="couponrule != null">
                couponRule = #{couponrule,jdbcType=INTEGER},
            </if>
            <if test="begindate != null">
                beginDate = #{begindate,jdbcType=BIGINT},
            </if>
            <if test="enddate != null">
                endDate = #{enddate,jdbcType=BIGINT},
            </if>
            <if test="coursenum != null">
                courseNum = #{coursenum,jdbcType=INTEGER},
            </if>
            <if test="hasnum != null">
                hasNum = #{hasnum,jdbcType=INTEGER},
            </if>
            <if test="cancelnum != null">
                cancelNum = #{cancelnum,jdbcType=INTEGER},
            </if>
            <if test="coursenuminput != null">
                courseNumInput = #{coursenuminput,jdbcType=INTEGER},
            </if>
            <if test="ordernum != null">
                orderNum = #{ordernum,jdbcType=INTEGER},
            </if>
            <if test="fav != null">
                fav = #{fav,jdbcType=BIGINT},
            </if>
            <if test="viplevel != null">
                vipLevel = #{viplevel,jdbcType=INTEGER},
            </if>
            <if test="cancelreason != null">
                cancelReason = #{cancelreason,jdbcType=INTEGER},
            </if>
            <if test="createdate != null">
                createDate = #{createdate,jdbcType=BIGINT},
            </if>
            <if test="lastmoddate != null">
                lastModDate = #{lastmoddate,jdbcType=BIGINT},
            </if>
            <if test="formatter != null">
                formatter = #{formatter,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=TINYINT},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    
    <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from qfd_sketch
        where id = #{id,jdbcType=BIGINT}
    </delete>
</mapper>


6.可以通过上面的修改后文件可以看到已经实现了我们的要求,但是sql id还是不满足我们的要求,应该改成纯粹的insert,update,delete

找到IntrospectedTable.java类的calculateXmlAttributes()方法,可以看到很多的setxxx方法带了具体的字符串参数,这个就是对应sql文件里面的sql id我们把对应的改改

protected void calculateXmlAttributes() {
        setIbatis2SqlMapPackage(calculateSqlMapPackage());
        setIbatis2SqlMapFileName(calculateIbatis2SqlMapFileName());
        setMyBatis3XmlMapperFileName(calculateMyBatis3XmlMapperFileName());
        setMyBatis3XmlMapperPackage(calculateSqlMapPackage());

        setIbatis2SqlMapNamespace(calculateIbatis2SqlMapNamespace());
        setMyBatis3FallbackSqlMapNamespace(calculateMyBatis3FallbackSqlMapNamespace());
        
        setSqlMapFullyQualifiedRuntimeTableName(calculateSqlMapFullyQualifiedRuntimeTableName());
        setSqlMapAliasedFullyQualifiedRuntimeTableName(calculateSqlMapAliasedFullyQualifiedRuntimeTableName());

        setCountByExampleStatementId("countByExample"); //$NON-NLS-1$
        setDeleteByExampleStatementId("deleteByExample"); //$NON-NLS-1$
        setDeleteByPrimaryKeyStatementId("deleteByPrimaryKey"); //$NON-NLS-1$
        setInsertStatementId("insert"); //$NON-NLS-1$
        setInsertSelectiveStatementId("insertSelective"); //$NON-NLS-1$
        setSelectAllStatementId("selectAll"); //$NON-NLS-1$
        setSelectByExampleStatementId("selectByExample"); //$NON-NLS-1$
        setSelectByExampleWithBLOBsStatementId("selectByExampleWithBLOBs"); //$NON-NLS-1$
        setSelectByPrimaryKeyStatementId("selectByPrimaryKey"); //$NON-NLS-1$
        setUpdateByExampleStatementId("updateByExample"); //$NON-NLS-1$
        setUpdateByExampleSelectiveStatementId("updateByExampleSelective"); //$NON-NLS-1$
        setUpdateByExampleWithBLOBsStatementId("updateByExampleWithBLOBs"); //$NON-NLS-1$
        setUpdateByPrimaryKeyStatementId("updateByPrimaryKey"); //$NON-NLS-1$
        setUpdateByPrimaryKeySelectiveStatementId("updateByPrimaryKeySelective"); //$NON-NLS-1$
        setUpdateByPrimaryKeyWithBLOBsStatementId("updateByPrimaryKeyWithBLOBs"); //$NON-NLS-1$
        setBaseResultMapId("BaseResultMap"); //$NON-NLS-1$
        setResultMapWithBLOBsId("ResultMapWithBLOBs"); //$NON-NLS-1$
        setExampleWhereClauseId("Example_Where_Clause"); //$NON-NLS-1$
        setBaseColumnListId("Base_Column_List"); //$NON-NLS-1$
        setBlobColumnListId("Blob_Column_List"); //$NON-NLS-1$
        setMyBatis3UpdateByExampleWhereClauseId("Update_By_Example_Where_Clause"); //$NON-NLS-1$
    }

修改后方法

protected void calculateXmlAttributes() {
        setIbatis2SqlMapPackage(calculateSqlMapPackage());
        setIbatis2SqlMapFileName(calculateIbatis2SqlMapFileName());
        setMyBatis3XmlMapperFileName(calculateMyBatis3XmlMapperFileName());
        setMyBatis3XmlMapperPackage(calculateSqlMapPackage());

        setIbatis2SqlMapNamespace(calculateIbatis2SqlMapNamespace());
        setMyBatis3FallbackSqlMapNamespace(calculateMyBatis3FallbackSqlMapNamespace());
        
        setSqlMapFullyQualifiedRuntimeTableName(calculateSqlMapFullyQualifiedRuntimeTableName());
        setSqlMapAliasedFullyQualifiedRuntimeTableName(calculateSqlMapAliasedFullyQualifiedRuntimeTableName());

        setCountByExampleStatementId("countByExample"); //$NON-NLS-1$
        setDeleteByExampleStatementId("deleteByExample"); //$NON-NLS-1$
        // setDeleteByPrimaryKeyStatementId("deleteByPrimaryKey"); //$NON-NLS-1$
        setDeleteByPrimaryKeyStatementId("delete"); // deleteByPrimaryKey改成delete
        setInsertStatementId("insert"); //$NON-NLS-1$
        // setInsertSelectiveStatementId("insertSelective"); //$NON-NLS-1$
        setInsertSelectiveStatementId("insert"); // insertSelective改成insert
        setSelectAllStatementId("selectAll"); //$NON-NLS-1$
        setSelectByExampleStatementId("selectByExample"); //$NON-NLS-1$
        setSelectByExampleWithBLOBsStatementId("selectByExampleWithBLOBs"); //$NON-NLS-1$
        setSelectByPrimaryKeyStatementId("selectByPrimaryKey"); //$NON-NLS-1$
        setUpdateByExampleStatementId("updateByExample"); //$NON-NLS-1$
        setUpdateByExampleSelectiveStatementId("updateByExampleSelective"); //$NON-NLS-1$
        setUpdateByExampleWithBLOBsStatementId("updateByExampleWithBLOBs"); //$NON-NLS-1$
        setUpdateByPrimaryKeyStatementId("updateByPrimaryKey"); //$NON-NLS-1$
        // setUpdateByPrimaryKeySelectiveStatementId("updateByPrimaryKeySelective"); //$NON-NLS-1$
        setUpdateByPrimaryKeySelectiveStatementId("update"); // updateByPrimaryKeySelective改成update
        setUpdateByPrimaryKeyWithBLOBsStatementId("updateByPrimaryKeyWithBLOBs"); //$NON-NLS-1$
        setBaseResultMapId("BaseResultMap"); //$NON-NLS-1$
        setResultMapWithBLOBsId("ResultMapWithBLOBs"); //$NON-NLS-1$
        setExampleWhereClauseId("Example_Where_Clause"); //$NON-NLS-1$
        setBaseColumnListId("Base_Column_List"); //$NON-NLS-1$
        setBlobColumnListId("Blob_Column_List"); //$NON-NLS-1$
        setMyBatis3UpdateByExampleWhereClauseId("Update_By_Example_Where_Clause"); //$NON-NLS-1$
    }

7.修改方法后我们再重新生成文件看看效果

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.test.dao.QfdSketchMapper">
    
    <resultMap id="BaseResultMap" type="com.test.domain.QfdSketch">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        <id column="id" jdbcType="BIGINT" property="id" />
        <result column="courseName" jdbcType="VARCHAR" property="coursename" />
        <result column="courseReq" jdbcType="VARCHAR" property="coursereq" />
        <result column="teaId" jdbcType="VARCHAR" property="teaid" />
        <result column="teaName" jdbcType="VARCHAR" property="teaname" />
        <result column="stuId" jdbcType="VARCHAR" property="stuid" />
        <result column="stuName" jdbcType="VARCHAR" property="stuname" />
        <result column="stuPhone" jdbcType="VARCHAR" property="stuphone" />
        <result column="textbookId" jdbcType="BIGINT" property="textbookid" />
        <result column="creator" jdbcType="VARCHAR" property="creator" />
        <result column="lastModifier" jdbcType="VARCHAR" property="lastmodifier" />
        <result column="countDate" jdbcType="INTEGER" property="countdate" />
        <result column="countTime" jdbcType="INTEGER" property="counttime" />
        <result column="countStu" jdbcType="INTEGER" property="countstu" />
        <result column="sketchType" jdbcType="INTEGER" property="sketchtype" />
        <result column="courseStyle" jdbcType="INTEGER" property="coursestyle" />
        <result column="classType" jdbcType="INTEGER" property="classtype" />
        <result column="process" jdbcType="INTEGER" property="process" />
        <result column="courseStatus" jdbcType="INTEGER" property="coursestatus" />
        <result column="pay" jdbcType="VARCHAR" property="pay" />
        <result column="perPay" jdbcType="VARCHAR" property="perpay" />
        <result column="couponPay" jdbcType="VARCHAR" property="couponpay" />
        <result column="originalPay" jdbcType="VARCHAR" property="originalpay" />
        <result column="couponRule" jdbcType="INTEGER" property="couponrule" />
        <result column="beginDate" jdbcType="BIGINT" property="begindate" />
        <result column="endDate" jdbcType="BIGINT" property="enddate" />
        <result column="courseNum" jdbcType="INTEGER" property="coursenum" />
        <result column="hasNum" jdbcType="INTEGER" property="hasnum" />
        <result column="cancelNum" jdbcType="INTEGER" property="cancelnum" />
        <result column="courseNumInput" jdbcType="INTEGER" property="coursenuminput" />
        <result column="orderNum" jdbcType="INTEGER" property="ordernum" />
        <result column="fav" jdbcType="BIGINT" property="fav" />
        <result column="vipLevel" jdbcType="INTEGER" property="viplevel" />
        <result column="cancelReason" jdbcType="INTEGER" property="cancelreason" />
        <result column="createDate" jdbcType="BIGINT" property="createdate" />
        <result column="lastModDate" jdbcType="BIGINT" property="lastmoddate" />
        <result column="formatter" jdbcType="VARCHAR" property="formatter" />
        <result column="status" jdbcType="TINYINT" property="status" />
    </resultMap>
    
    <sql id="Base_Column_List">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        id, courseName, courseReq, teaId, teaName, stuId, stuName, stuPhone, textbookId, 
        creator, lastModifier, countDate, countTime, countStu, sketchType, courseStyle, classType, 
        process, courseStatus, pay, perPay, couponPay, originalPay, couponRule, beginDate, 
        endDate, courseNum, hasNum, cancelNum, courseNumInput, orderNum, fav, vipLevel, cancelReason, 
        createDate, lastModDate, formatter, status
    </sql>
    
    <insert id="insert" parameterType="com.test.domain.QfdSketch">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        insert into qfd_sketch
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="id != null">
                id,
            </if>
            <if test="coursename != null">
                courseName,
            </if>
            <if test="coursereq != null">
                courseReq,
            </if>
            <if test="teaid != null">
                teaId,
            </if>
            <if test="teaname != null">
                teaName,
            </if>
            <if test="stuid != null">
                stuId,
            </if>
            <if test="stuname != null">
                stuName,
            </if>
            <if test="stuphone != null">
                stuPhone,
            </if>
            <if test="textbookid != null">
                textbookId,
            </if>
            <if test="creator != null">
                creator,
            </if>
            <if test="lastmodifier != null">
                lastModifier,
            </if>
            <if test="countdate != null">
                countDate,
            </if>
            <if test="counttime != null">
                countTime,
            </if>
            <if test="countstu != null">
                countStu,
            </if>
            <if test="sketchtype != null">
                sketchType,
            </if>
            <if test="coursestyle != null">
                courseStyle,
            </if>
            <if test="classtype != null">
                classType,
            </if>
            <if test="process != null">
                process,
            </if>
            <if test="coursestatus != null">
                courseStatus,
            </if>
            <if test="pay != null">
                pay,
            </if>
            <if test="perpay != null">
                perPay,
            </if>
            <if test="couponpay != null">
                couponPay,
            </if>
            <if test="originalpay != null">
                originalPay,
            </if>
            <if test="couponrule != null">
                couponRule,
            </if>
            <if test="begindate != null">
                beginDate,
            </if>
            <if test="enddate != null">
                endDate,
            </if>
            <if test="coursenum != null">
                courseNum,
            </if>
            <if test="hasnum != null">
                hasNum,
            </if>
            <if test="cancelnum != null">
                cancelNum,
            </if>
            <if test="coursenuminput != null">
                courseNumInput,
            </if>
            <if test="ordernum != null">
                orderNum,
            </if>
            <if test="fav != null">
                fav,
            </if>
            <if test="viplevel != null">
                vipLevel,
            </if>
            <if test="cancelreason != null">
                cancelReason,
            </if>
            <if test="createdate != null">
                createDate,
            </if>
            <if test="lastmoddate != null">
                lastModDate,
            </if>
            <if test="formatter != null">
                formatter,
            </if>
            <if test="status != null">
                status,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="id != null">
                #{id,jdbcType=BIGINT},
            </if>
            <if test="coursename != null">
                #{coursename,jdbcType=VARCHAR},
            </if>
            <if test="coursereq != null">
                #{coursereq,jdbcType=VARCHAR},
            </if>
            <if test="teaid != null">
                #{teaid,jdbcType=VARCHAR},
            </if>
            <if test="teaname != null">
                #{teaname,jdbcType=VARCHAR},
            </if>
            <if test="stuid != null">
                #{stuid,jdbcType=VARCHAR},
            </if>
            <if test="stuname != null">
                #{stuname,jdbcType=VARCHAR},
            </if>
            <if test="stuphone != null">
                #{stuphone,jdbcType=VARCHAR},
            </if>
            <if test="textbookid != null">
                #{textbookid,jdbcType=BIGINT},
            </if>
            <if test="creator != null">
                #{creator,jdbcType=VARCHAR},
            </if>
            <if test="lastmodifier != null">
                #{lastmodifier,jdbcType=VARCHAR},
            </if>
            <if test="countdate != null">
                #{countdate,jdbcType=INTEGER},
            </if>
            <if test="counttime != null">
                #{counttime,jdbcType=INTEGER},
            </if>
            <if test="countstu != null">
                #{countstu,jdbcType=INTEGER},
            </if>
            <if test="sketchtype != null">
                #{sketchtype,jdbcType=INTEGER},
            </if>
            <if test="coursestyle != null">
                #{coursestyle,jdbcType=INTEGER},
            </if>
            <if test="classtype != null">
                #{classtype,jdbcType=INTEGER},
            </if>
            <if test="process != null">
                #{process,jdbcType=INTEGER},
            </if>
            <if test="coursestatus != null">
                #{coursestatus,jdbcType=INTEGER},
            </if>
            <if test="pay != null">
                #{pay,jdbcType=VARCHAR},
            </if>
            <if test="perpay != null">
                #{perpay,jdbcType=VARCHAR},
            </if>
            <if test="couponpay != null">
                #{couponpay,jdbcType=VARCHAR},
            </if>
            <if test="originalpay != null">
                #{originalpay,jdbcType=VARCHAR},
            </if>
            <if test="couponrule != null">
                #{couponrule,jdbcType=INTEGER},
            </if>
            <if test="begindate != null">
                #{begindate,jdbcType=BIGINT},
            </if>
            <if test="enddate != null">
                #{enddate,jdbcType=BIGINT},
            </if>
            <if test="coursenum != null">
                #{coursenum,jdbcType=INTEGER},
            </if>
            <if test="hasnum != null">
                #{hasnum,jdbcType=INTEGER},
            </if>
            <if test="cancelnum != null">
                #{cancelnum,jdbcType=INTEGER},
            </if>
            <if test="coursenuminput != null">
                #{coursenuminput,jdbcType=INTEGER},
            </if>
            <if test="ordernum != null">
                #{ordernum,jdbcType=INTEGER},
            </if>
            <if test="fav != null">
                #{fav,jdbcType=BIGINT},
            </if>
            <if test="viplevel != null">
                #{viplevel,jdbcType=INTEGER},
            </if>
            <if test="cancelreason != null">
                #{cancelreason,jdbcType=INTEGER},
            </if>
            <if test="createdate != null">
                #{createdate,jdbcType=BIGINT},
            </if>
            <if test="lastmoddate != null">
                #{lastmoddate,jdbcType=BIGINT},
            </if>
            <if test="formatter != null">
                #{formatter,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                #{status,jdbcType=TINYINT},
            </if>
        </trim>
    </insert>
    
    <update id="update" parameterType="com.test.domain.QfdSketch">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        update qfd_sketch
        <set>
            <if test="coursename != null">
                courseName = #{coursename,jdbcType=VARCHAR},
            </if>
            <if test="coursereq != null">
                courseReq = #{coursereq,jdbcType=VARCHAR},
            </if>
            <if test="teaid != null">
                teaId = #{teaid,jdbcType=VARCHAR},
            </if>
            <if test="teaname != null">
                teaName = #{teaname,jdbcType=VARCHAR},
            </if>
            <if test="stuid != null">
                stuId = #{stuid,jdbcType=VARCHAR},
            </if>
            <if test="stuname != null">
                stuName = #{stuname,jdbcType=VARCHAR},
            </if>
            <if test="stuphone != null">
                stuPhone = #{stuphone,jdbcType=VARCHAR},
            </if>
            <if test="textbookid != null">
                textbookId = #{textbookid,jdbcType=BIGINT},
            </if>
            <if test="creator != null">
                creator = #{creator,jdbcType=VARCHAR},
            </if>
            <if test="lastmodifier != null">
                lastModifier = #{lastmodifier,jdbcType=VARCHAR},
            </if>
            <if test="countdate != null">
                countDate = #{countdate,jdbcType=INTEGER},
            </if>
            <if test="counttime != null">
                countTime = #{counttime,jdbcType=INTEGER},
            </if>
            <if test="countstu != null">
                countStu = #{countstu,jdbcType=INTEGER},
            </if>
            <if test="sketchtype != null">
                sketchType = #{sketchtype,jdbcType=INTEGER},
            </if>
            <if test="coursestyle != null">
                courseStyle = #{coursestyle,jdbcType=INTEGER},
            </if>
            <if test="classtype != null">
                classType = #{classtype,jdbcType=INTEGER},
            </if>
            <if test="process != null">
                process = #{process,jdbcType=INTEGER},
            </if>
            <if test="coursestatus != null">
                courseStatus = #{coursestatus,jdbcType=INTEGER},
            </if>
            <if test="pay != null">
                pay = #{pay,jdbcType=VARCHAR},
            </if>
            <if test="perpay != null">
                perPay = #{perpay,jdbcType=VARCHAR},
            </if>
            <if test="couponpay != null">
                couponPay = #{couponpay,jdbcType=VARCHAR},
            </if>
            <if test="originalpay != null">
                originalPay = #{originalpay,jdbcType=VARCHAR},
            </if>
            <if test="couponrule != null">
                couponRule = #{couponrule,jdbcType=INTEGER},
            </if>
            <if test="begindate != null">
                beginDate = #{begindate,jdbcType=BIGINT},
            </if>
            <if test="enddate != null">
                endDate = #{enddate,jdbcType=BIGINT},
            </if>
            <if test="coursenum != null">
                courseNum = #{coursenum,jdbcType=INTEGER},
            </if>
            <if test="hasnum != null">
                hasNum = #{hasnum,jdbcType=INTEGER},
            </if>
            <if test="cancelnum != null">
                cancelNum = #{cancelnum,jdbcType=INTEGER},
            </if>
            <if test="coursenuminput != null">
                courseNumInput = #{coursenuminput,jdbcType=INTEGER},
            </if>
            <if test="ordernum != null">
                orderNum = #{ordernum,jdbcType=INTEGER},
            </if>
            <if test="fav != null">
                fav = #{fav,jdbcType=BIGINT},
            </if>
            <if test="viplevel != null">
                vipLevel = #{viplevel,jdbcType=INTEGER},
            </if>
            <if test="cancelreason != null">
                cancelReason = #{cancelreason,jdbcType=INTEGER},
            </if>
            <if test="createdate != null">
                createDate = #{createdate,jdbcType=BIGINT},
            </if>
            <if test="lastmoddate != null">
                lastModDate = #{lastmoddate,jdbcType=BIGINT},
            </if>
            <if test="formatter != null">
                formatter = #{formatter,jdbcType=VARCHAR},
            </if>
            <if test="status != null">
                status = #{status,jdbcType=TINYINT},
            </if>
        </set>
        where id = #{id,jdbcType=BIGINT}
    </update>
    
    <delete id="delete" parameterType="java.lang.Long">
        <!--
          WARNING - @mbg.generated
          This element is automatically generated by MyBatis Generator, do not modify.
        -->
        delete from qfd_sketch
        where id = #{id,jdbcType=BIGINT}
    </delete>
</mapper>

8.已经改成比较符合我们规范和使用的xml文件了,看着很让人舒服不别扭;小结:这些修改代码都是源码生成器必经的逻辑,所以有兴趣继续改造的同学可以继续断点查看并按自己的习惯修改,我只是大概讲了那些部分都是关键地方,下一篇我应该会讲解如何增加自定义sql了,大家有兴趣继续学习的请不要错过咯,再次谢谢大家的支持


目录
相关文章
|
2月前
|
SQL Java 测试技术
3、Mybatis-Plus 自定义sql语句
这篇文章介绍了如何在Mybatis-Plus框架中使用自定义SQL语句进行数据库操作。内容包括文档结构、编写mapper文件、mapper.xml文件的解释说明、在mapper接口中定义方法、在mapper.xml文件中实现接口方法的SQL语句,以及如何在单元测试中测试自定义的SQL语句,并展示了测试结果。
3、Mybatis-Plus 自定义sql语句
|
17天前
|
前端开发 Java Apache
Springboot整合shiro,带你学会shiro,入门级别教程,由浅入深,完整代码案例,各位项目想加这个模块的人也可以看这个,又或者不会mybatis-plus的也可以看这个
本文详细讲解了如何整合Apache Shiro与Spring Boot项目,包括数据库准备、项目配置、实体类、Mapper、Service、Controller的创建和配置,以及Shiro的配置和使用。
136 1
Springboot整合shiro,带你学会shiro,入门级别教程,由浅入深,完整代码案例,各位项目想加这个模块的人也可以看这个,又或者不会mybatis-plus的也可以看这个
|
10天前
|
SQL Java 数据库连接
mybatis使用四:dao接口参数与mapper 接口中SQL的对应和对应方式的总结,MyBatis的parameterType传入参数类型
这篇文章是关于MyBatis中DAO接口参数与Mapper接口中SQL的对应关系,以及如何使用parameterType传入参数类型的详细总结。
22 10
|
1月前
|
SQL XML Java
mybatis复习03,动态SQL,if,choose,where,set,trim标签及foreach标签的用法
文章介绍了MyBatis中动态SQL的用法,包括if、choose、where、set和trim标签,以及foreach标签的详细使用。通过实际代码示例,展示了如何根据条件动态构建查询、更新和批量插入操作的SQL语句。
mybatis复习03,动态SQL,if,choose,where,set,trim标签及foreach标签的用法
|
2月前
|
XML 缓存 Java
一文讲明Mybatis 的使用 超详细 【爆肝两万字教程】
文章提供了一份详尽的Mybatis使用教程,涵盖了Mybatis的简介、环境搭建、基本操作、配置解析、日志使用、分页、注解开发、多对一和一对多关系处理、动态SQL以及缓存机制等方面的内容,并提供了相应的代码示例和测试用例。
一文讲明Mybatis 的使用 超详细 【爆肝两万字教程】
|
1月前
|
SQL XML Java
mybatis :sqlmapconfig.xml配置 ++++Mapper XML 文件(sql/insert/delete/update/select)(增删改查)用法
当然,这些仅是MyBatis功能的初步介绍。MyBatis还提供了高级特性,如动态SQL、类型处理器、插件等,可以进一步提供对数据库交互的强大支持和灵活性。希望上述内容对您理解MyBatis的基本操作有所帮助。在实际使用中,您可能还需要根据具体的业务要求调整和优化SQL语句和配置。
39 1
|
2月前
|
前端开发 开发者
Vaadin Grid的秘密武器:打造超凡脱俗的数据展示体验!
【8月更文挑战第31天】赵萌是一位热爱UI设计的前端开发工程师。在公司内部项目中,她面临大量用户数据展示的挑战,并选择了功能强大的Vaadin Grid来解决。她在技术博客上分享了这一过程,介绍了Vaadin Grid的基本概念及其丰富的内置功能。通过自定义列和模板,赵萌展示了如何实现复杂的数据展示。
35 0
|
2月前
|
SQL 开发框架 .NET
深入解析Entity Framework Core中的自定义SQL查询与Raw SQL技巧:从基础到高级应用的全面指南,附带示例代码与最佳实践建议
【8月更文挑战第31天】本文详细介绍了如何在 Entity Framework Core (EF Core) 中使用自定义 SQL 查询与 Raw SQL。首先,通过创建基于 EF Core 的项目并配置数据库上下文,定义领域模型。然后,使用 `FromSqlRaw` 和 `FromSqlInterpolated` 方法执行自定义 SQL 查询。此外,还展示了如何使用 Raw SQL 进行数据更新和删除操作。最后,通过结合 LINQ 和 Raw SQL 构建动态 SQL 语句,处理复杂查询场景。本文提供了具体代码示例,帮助读者理解和应用这些技术,提升数据访问层的效率和灵活性。
126 0
|
2月前
|
SQL Java 数据库连接
Spring Boot联手MyBatis,打造开发利器:从入门到精通,实战教程带你飞越编程高峰!
【8月更文挑战第29天】Spring Boot与MyBatis分别是Java快速开发和持久层框架的优秀代表。本文通过整合Spring Boot与MyBatis,展示了如何在项目中添加相关依赖、配置数据源及MyBatis,并通过实战示例介绍了实体类、Mapper接口及Controller的创建过程。通过本文,你将学会如何利用这两款工具提高开发效率,实现数据的增删查改等复杂操作,为实际项目开发提供有力支持。
106 0
|
2月前
|
Java 关系型数据库 MySQL