Mybatis3 反向工程

想要生成这种xml格式的sql语句,看这边:

<?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="suwaaaa.author.springboot_redis.dao.UserMapper">
  <resultMap id="BaseResultMap" type="suwaaaa.author.springboot_redis.damain.User">
    <id column="userId" jdbcType="INTEGER" property="userid" />
    <result column="age" jdbcType="INTEGER" property="age" />
    <result column="name" jdbcType="CHAR" property="name" />
    <result column="address" jdbcType="VARCHAR" property="address" />
    <result column="passcode" jdbcType="VARCHAR" property="passcode" />
    <result column="phone" jdbcType="INTEGER" property="phone" />
    <result column="mail" jdbcType="VARCHAR" property="mail" />
    <result column="vip" jdbcType="BIT" property="vip" />
    <result column="creat_time" jdbcType="INTEGER" property="creatTime" />
  </resultMap>
  <sql id="Base_Column_List">
    userId, age, name, address, passcode, phone, mail, vip, creat_time
  </sql>
  <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
    select 
    <include refid="Base_Column_List" />
    from user
    where userId = #{userid,jdbcType=INTEGER}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.Integer">
    delete from user
    where userId = #{userid,jdbcType=INTEGER}
  </delete>
  <insert id="insert" parameterType="suwaaaa.author.springboot_redis.damain.User">
    insert into user (userId, age, name, 
      address, passcode, phone, 
      mail, vip, creat_time)
    values (#{userid,jdbcType=INTEGER}, #{age,jdbcType=INTEGER}, #{name,jdbcType=CHAR}, 
      #{address,jdbcType=VARCHAR}, #{passcode,jdbcType=VARCHAR}, #{phone,jdbcType=INTEGER}, 
      #{mail,jdbcType=VARCHAR}, #{vip,jdbcType=BIT}, #{creatTime,jdbcType=INTEGER})
  </insert>
  <insert id="insertSelective" parameterType="suwaaaa.author.springboot_redis.damain.User">
    insert into user
    <trim prefix="(" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        userId,
      </if>
      <if test="age != null">
        age,
      </if>
      <if test="name != null">
        name,
      </if>
      <if test="address != null">
        address,
      </if>
      <if test="passcode != null">
        passcode,
      </if>
      <if test="phone != null">
        phone,
      </if>
      <if test="mail != null">
        mail,
      </if>
      <if test="vip != null">
        vip,
      </if>
      <if test="creatTime != null">
        creat_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides=",">
      <if test="userid != null">
        #{userid,jdbcType=INTEGER},
      </if>
      <if test="age != null">
        #{age,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        #{name,jdbcType=CHAR},
      </if>
      <if test="address != null">
        #{address,jdbcType=VARCHAR},
      </if>
      <if test="passcode != null">
        #{passcode,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        #{phone,jdbcType=INTEGER},
      </if>
      <if test="mail != null">
        #{mail,jdbcType=VARCHAR},
      </if>
      <if test="vip != null">
        #{vip,jdbcType=BIT},
      </if>
      <if test="creatTime != null">
        #{creatTime,jdbcType=INTEGER},
      </if>
    </trim>
  </insert>
  <update id="updateByPrimaryKeySelective" parameterType="suwaaaa.author.springboot_redis.damain.User">
    update user
    <set>
      <if test="age != null">
        age = #{age,jdbcType=INTEGER},
      </if>
      <if test="name != null">
        name = #{name,jdbcType=CHAR},
      </if>
      <if test="address != null">
        address = #{address,jdbcType=VARCHAR},
      </if>
      <if test="passcode != null">
        passcode = #{passcode,jdbcType=VARCHAR},
      </if>
      <if test="phone != null">
        phone = #{phone,jdbcType=INTEGER},
      </if>
      <if test="mail != null">
        mail = #{mail,jdbcType=VARCHAR},
      </if>
      <if test="vip != null">
        vip = #{vip,jdbcType=BIT},
      </if>
      <if test="creatTime != null">
        creat_time = #{creatTime,jdbcType=INTEGER},
      </if>
    </set>
    where userId = #{userid,jdbcType=INTEGER}
  </update>
  <update id="updateByPrimaryKey" parameterType="suwaaaa.author.springboot_redis.damain.User">
    update user
    set age = #{age,jdbcType=INTEGER},
      name = #{name,jdbcType=CHAR},
      address = #{address,jdbcType=VARCHAR},
      passcode = #{passcode,jdbcType=VARCHAR},
      phone = #{phone,jdbcType=INTEGER},
      mail = #{mail,jdbcType=VARCHAR},
      vip = #{vip,jdbcType=BIT},
      creat_time = #{creatTime,jdbcType=INTEGER}
    where userId = #{userid,jdbcType=INTEGER}
  </update>
</mapper>```

(Mybatis3)::
generatorConfig.xml 需要这样写,

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN" "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">
<generatorConfiguration>

	<classPathEntry
		location="E:\ecplise\workspace\spring_boot_test\mysql-connector-java-5.1.39-bin.jar" />


	<context id="context1" targetRuntime="MyBatis3">
		<!-- 生成数据库的注释信息,并且禁止在 注释中生成日期 -->
		<commentGenerator>
			<property name="suppressDate" value="true" />
			<!-- <property name="addRemarkComments" value="true"/> -->
			<property name="suppressAllComments" value="true" />
		</commentGenerator>

		<!-- 数据库连接信息 -->
		<jdbcConnection
			connectionURL="jdbc:mysql://localhost:3306/springboot_redis?serverTimezone=GMT"
			driverClass="com.mysql.jdbc.Driver" password="123456" userId="root" />

		<!-- 生成实体类地址 -->
		<!-- targetPackage 指定 model 类的包名, targetProject指定生成的 model 放在 eclipse 的哪个工程下面 -->
		<javaModelGenerator
			targetPackage="suwaaaa.author.springboot_redis.damain"
			targetProject="springboot_redis\src\main\java">
			<property name="enableSubPackages" value="false" />
			<property name="trimStrings" value="false" />
		</javaModelGenerator>
		
		<sqlMapGenerator targetPackage="suwaaaa.author.springboot_redis.mapper"
        targetProject="springboot_redis\src\main\java">
        <property name="enableSubPackages" value="false"/>
        </sqlMapGenerator>
        
        

		<!-- 生成DAO地址 -->
		<javaClientGenerator type="XMLMAPPER"
        targetPackage="suwaaaa.author.springboot_redis.dao"

        targetProject="springboot_redis\src\main\java">
        <property name="enableSubPackages" value="false"/>
        </javaClientGenerator>
        
		<!-- <javaClientGenerator
			targetPackage="suwaaaa.author.springboot_redis.dao"
			targetProject="springboot_redis\src\main\java" type="XMLMAPPER" >
			</javaClientGenerator> -->
		<!-- 在targetPackage的基础上,在package下生成$schema包,默认为false -->
		<!-- <property name="enableSubPackages" value="false"/> -->

		<!-- 数据库表名及对应的 Java 模型类名 -->
		<!-- <table schema="springboot_redis" tableName="user">
			<columnOverride column="AGE" property="age" />
			<columnOverride column="NAME" property="name" />
			<columnOverride column="ADDRESS" property="address" />
			<columnOverride column="PHONE" property="phone" />
			<columnOverride column="MAIL" property="mail" />
			<columnOverride column="VIP" property="vip" />
			<columnOverride column="USERID" property="userId" />
			忽略列,不生成bean 字段
			<ignoreColumn column="passcode" />
			<ignoreColumn column="creat_time" />
		</table> -->
		 <table tableName="user" domainObjectName="User"
                   enableCountByExample="false"
                   enableUpdateByExample="false"
                   enableDeleteByExample="false"
                   enableSelectByExample="false"
                   selectByExampleQueryId="false"/>
	</context>
</generatorConfiguration>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值