环境: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