環境:mybatis-generator版本是1.3.5sql
問題:在生成xml、mapper時,文件內容重複生成。api
<?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="www.sanyue.mapper.TestMapper"> <resultMap id="BaseResultMap" type="www.sanyue.domain.po.Test"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="name" jdbcType="VARCHAR" property="name" /> <result column="indate" jdbcType="TIMESTAMP" property="indate" /> <result column="_mycat_op_time" jdbcType="BIGINT" property="mycatOpTime" /> </resultMap> <sql id="Base_Column_List"> id, `name`, indate, _mycat_op_time </sql> <select id="selectByPrimaryKey" parameterType="www.sanyue.domain.po.TestKey" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from zrx_test where id = #{id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="www.sanyue.domain.po.TestKey"> delete from zrx_test where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="www.sanyue.domain.po.Test"> insert into zrx_test (id, `name`, indate, _mycat_op_time) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{indate,jdbcType=TIMESTAMP}, #{mycatOpTime,jdbcType=BIGINT}) </insert> <insert id="insertSelective" parameterType="www.sanyue.domain.po.Test"> insert into zrx_test <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="name != null"> `name`, </if> <if test="indate != null"> indate, </if> <if test="mycatOpTime != null"> _mycat_op_time, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=INTEGER}, </if> <if test="name != null"> #{name,jdbcType=VARCHAR}, </if> <if test="indate != null"> #{indate,jdbcType=TIMESTAMP}, </if> <if test="mycatOpTime != null"> #{mycatOpTime,jdbcType=BIGINT}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="www.sanyue.domain.po.Test"> update zrx_test <set> <if test="name != null"> `name` = #{name,jdbcType=VARCHAR}, </if> <if test="indate != null"> indate = #{indate,jdbcType=TIMESTAMP}, </if> <if test="mycatOpTime != null"> _mycat_op_time = #{mycatOpTime,jdbcType=BIGINT}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="www.sanyue.domain.po.Test"> update zrx_test set `name` = #{name,jdbcType=VARCHAR}, indate = #{indate,jdbcType=TIMESTAMP}, _mycat_op_time = #{mycatOpTime,jdbcType=BIGINT} where id = #{id,jdbcType=INTEGER} </update> <resultMap id="BaseResultMap" type="www.sanyue.domain.po.Test"> <id column="id" jdbcType="INTEGER" property="id" /> <result column="name" jdbcType="VARCHAR" property="name" /> <result column="indate" jdbcType="TIMESTAMP" property="indate" /> </resultMap> <sql id="Base_Column_List"> id, `name`, indate </sql> <select id="selectByPrimaryKey" parameterType="www.sanyue.domain.po.TestKey" resultMap="BaseResultMap"> select <include refid="Base_Column_List" /> from zrx_test where id = #{id,jdbcType=INTEGER} </select> <delete id="deleteByPrimaryKey" parameterType="www.sanyue.domain.po.TestKey"> delete from zrx_test where id = #{id,jdbcType=INTEGER} </delete> <insert id="insert" parameterType="www.sanyue.domain.po.Test"> insert into zrx_test (id, `name`, indate ) values (#{id,jdbcType=INTEGER}, #{name,jdbcType=VARCHAR}, #{indate,jdbcType=TIMESTAMP} ) </insert> <insert id="insertSelective" parameterType="www.sanyue.domain.po.Test"> insert into zrx_test <trim prefix="(" suffix=")" suffixOverrides=","> <if test="id != null"> id, </if> <if test="name != null"> `name`, </if> <if test="indate != null"> indate, </if> </trim> <trim prefix="values (" suffix=")" suffixOverrides=","> <if test="id != null"> #{id,jdbcType=INTEGER}, </if> <if test="name != null"> #{name,jdbcType=VARCHAR}, </if> <if test="indate != null"> #{indate,jdbcType=TIMESTAMP}, </if> </trim> </insert> <update id="updateByPrimaryKeySelective" parameterType="www.sanyue.domain.po.Test"> update zrx_test <set> <if test="name != null"> `name` = #{name,jdbcType=VARCHAR}, </if> <if test="indate != null"> indate = #{indate,jdbcType=TIMESTAMP}, </if> </set> where id = #{id,jdbcType=INTEGER} </update> <update id="updateByPrimaryKey" parameterType="www.sanyue.domain.po.Test"> update zrx_test set `name` = #{name,jdbcType=VARCHAR}, indate = #{indate,jdbcType=TIMESTAMP} where id = #{id,jdbcType=INTEGER} </update> </mapper>
解決方案:mybatis
在配置文件中有如下一段配置內容:app
這個元素很是有用,相信不少人都有過這樣的需求,就是但願MBG生成的代碼中能夠包含**註釋信息**,具體就是生成表或字段的備註信息。dom
使用這個元素就能很簡單的實現咱們想要的功能。這裏先介紹該元素,介紹完後會舉例如何擴展實現該功能。ide
該元素有一個可選屬性type
,能夠指定用戶的實現類,該類須要實現org.mybatis.generator.api.CommentGenerator
接口。並且必有一個默認的構造方法。這個屬性接收默認的特殊值DEFAULT
,會使用默認的實現類org.mybatis.generator.internal.DefaultCommentGenerator
。spa
默認的實現類中提供了兩個可選屬性,須要經過<property>
屬性進行配置。版本控制
suppressAllComments
:**阻止**生成註釋,默認爲false
suppressDate
:**阻止**生成的註釋包含時間戳,默認爲false
通常狀況下因爲MBG生成的註釋信息沒有任何價值,並且有時間戳的狀況下每次生成的註釋都不同,使用**版本控制**的時候每次都會提交,於是通常狀況下咱們都會屏蔽註釋信息,能夠以下配置:code
將節點commentGenerator中的suppressAllComments屬性刪除。再次生成xml、dao時就不會重複生成了。xml