mybatis mybatis-generator 代码自动生成工具

一、简介

mybatis generator是很好用的mybatis自动代码生成工具。最近公司使用maven和mybatis开发项目,手动写入一个个实体类和mapper还有xml配置文件感觉会很麻烦,使用mybatis generator只需要简单的配置就能完成我们的工作,这里简述一下开发步骤。

二、开发流程

2.1 创建maven项目

我们选择开发工具创建maven项目,我这里使用myeclipse开发,建议使用eclipse或者idea开发。 
这里写图片描述

2.2 在pom配置文件中加入依赖包

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>mybatis-generator-base</groupId>
  <artifactId>mybatis-generator-base</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <name/>
  <description/>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jstl</artifactId>
      <version>1.2</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet.jsp</groupId>
      <artifactId>jsp-api</artifactId>
      <version>2.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.annotation</artifactId>
      <version>3.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.ejb</artifactId>
      <version>3.0.1</version>
    </dependency>
    <dependency>
      <groupId>org.jboss.weld</groupId>
      <artifactId>weld-osgi-bundle</artifactId>
      <version>1.0.1-SP3</version>
    </dependency>
    <dependency>
      <groupId>org.glassfish</groupId>
      <artifactId>javax.servlet</artifactId>
      <version>3.0.1</version>
    </dependency>
    <!--测试框架  -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
    </dependency>
    <!-- Mysql -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.2.7</version>
    </dependency>
    <!-- Mysql 依赖 -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>5.1.6</version>
    </dependency>
    <!--生成代码插件-->
    <dependency>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-core</artifactId>
        <version>1.3.2</version>
        <type>jar</type>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
      </plugin>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.6</source>
          <target>1.6</target>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85

2.3 新建生成代码的配置文件mybatis-generator-config.xml

将配置文件配置在合适的位置就可以,但是要访问的到,我这里放置在resources文件下。

<?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>
    <context id="prod">
        <!-- RowBounds pagination -->
        <plugin type="org.mybatis.generator.plugins.RowBoundsPlugin" />
        <plugin type="org.mybatis.generator.plugins.CaseInsensitiveLikePlugin" />
        <plugin type="org.mybatis.generator.plugins.SerializablePlugin" />

        <commentGenerator>
            <property name="suppressDate" value="true" />
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <!-- jdbc连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
            connectionURL="jdbc:mysql://127.0.0.1:3306/generator" userId="root"
            password="123456" />

        <javaModelGenerator targetPackage="com.mybatis.entity"
            targetProject="src/main/java">
            <!-- 是否针对string类型的字段在set的时候进行trim调用 -->
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
        <sqlMapGenerator targetPackage="mappers" targetProject="src/main/java" />
        <javaClientGenerator targetPackage="com.mybatis.mapper"
            targetProject="src/main/java" type="XMLMAPPER" />

        <table tableName="wx_ranking_flow" domainObjectName="WxRankingFlow">

        </table>

    </context>
</generatorConfiguration>
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35

(1)在javaModelGenerator标签下配置你需要生成的数据库实体的地址 
(2)在sqlMapGenerator标签下配置mysql的xml配置文件 
(3)在javaClientGenerator标签下配置mapper方法 
(4)在table标签下配置数据库的表面和生成实体的表名

2.4 新建批处理类main方法

package com.mybatis.test;

import org.mybatis.generator.api.ShellRunner;

public class App {

    public static void main(String[] args) {
        args = new String[] { "-configfile", "src\\main\\resources\\mybatis-generator-config.xml", "-overwrite" };
        ShellRunner.main(args);
    }

}

 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

这里要处理的就是我们的mybatis-generator-config.xml配置文件,路径一定要对应我们的存放路径。 
执行main方法就可以生成对应的实体和xml配置文件了。 
这里写图片描述 
我们会发现我们生成了两个实体对象,一个是数据库映射对象,一个是Example对象。Example对象就是为了方便我们执行sql操作的类,可以使用Example类进行数据库的条件查询。同时mybatis-generator还帮助我们生成了sql的CRUD等操作。

WxRankingFlowMapper接口

package com.mybatis.mapper;

import java.util.List;

import com.mybatis.entity.WxRankingFlow;
import com.mybatis.entity.WxRankingFlowExample;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.session.RowBounds;

public interface WxRankingFlowMapper {
    int countByExample(WxRankingFlowExample example);

    int deleteByExample(WxRankingFlowExample example);

    int deleteByPrimaryKey(String rId);

    int insert(WxRankingFlow record);

    int insertSelective(WxRankingFlow record);

    List<WxRankingFlow> selectByExampleWithRowbounds(WxRankingFlowExample example, RowBounds rowBounds);

    List<WxRankingFlow> selectByExample(WxRankingFlowExample example);

    WxRankingFlow selectByPrimaryKey(String rId);

    int updateByExampleSelective(@Param("record") WxRankingFlow record, @Param("example") WxRankingFlowExample example);

    int updateByExample(@Param("record") WxRankingFlow record, @Param("example") WxRankingFlowExample example);

    int updateByPrimaryKeySelective(WxRankingFlow record);

    int updateByPrimaryKey(WxRankingFlow record);
}
 
 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34

WxRankingFlowMapper.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.mybatis.mapper.WxRankingFlowMapper" >
  <resultMap id="BaseResultMap" type="com.mybatis.entity.WxRankingFlow" >
    <id column="r_id" property="rId" jdbcType="VARCHAR" />
    <result column="r_gift_date" property="rGiftDate" jdbcType="VARCHAR" />
    <result column="r_sid" property="rSid" jdbcType="VARCHAR" />
    <result column="r_card_no" property="rCardNo" jdbcType="VARCHAR" />
    <result column="r_card_name" property="rCardName" jdbcType="VARCHAR" />
    <result column="r_re_openid" property="rReOpenid" jdbcType="VARCHAR" />
    <result column="r_number" property="rNumber" jdbcType="INTEGER" />
    <result column="r_chain_code" property="rChainCode" jdbcType="VARCHAR" />
    <result column="r_chain_id" property="rChainId" jdbcType="VARCHAR" />
    <result column="r_chain_name" property="rChainName" jdbcType="VARCHAR" />
    <result column="r_total_amount" property="rTotalAmount" jdbcType="INTEGER" />
    <result column="r_total_count" property="rTotalCount" jdbcType="INTEGER" />
    <result column="r_praise_count" property="rPraiseCount" jdbcType="INTEGER" />
    <result column="r_create_time" property="rCreateTime" jdbcType="TIMESTAMP" />
    <result column="r_update_time" property="rUpdateTime" jdbcType="TIMESTAMP" />
  </resultMap>
  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
  </sql>
  <sql id="Base_Column_List" >
    r_id, r_gift_date, r_sid, r_card_no, r_card_name, r_re_openid, r_number, r_chain_code, 
    r_chain_id, r_chain_name, r_total_amount, r_total_count, r_praise_count, r_create_time, 
    r_update_time
  </sql>
  <select id="selectByExample" resultMap="BaseResultMap" parameterType="com.mybatis.entity.WxRankingFlowExample" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from wx_ranking_flow
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
  <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.String" >
    select 
    <include refid="Base_Column_List" />
    from wx_ranking_flow
    where r_id = #{rId,jdbcType=VARCHAR}
  </select>
  <delete id="deleteByPrimaryKey" parameterType="java.lang.String" >
    delete from wx_ranking_flow
    where r_id = #{rId,jdbcType=VARCHAR}
  </delete>
  <delete id="deleteByExample" parameterType="com.mybatis.entity.WxRankingFlowExample" >
    delete from wx_ranking_flow
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </delete>
  <insert id="insert" parameterType="com.mybatis.entity.WxRankingFlow" >
    insert into wx_ranking_flow (r_id, r_gift_date, r_sid, 
      r_card_no, r_card_name, r_re_openid, 
      r_number, r_chain_code, r_chain_id, 
      r_chain_name, r_total_amount, r_total_count, 
      r_praise_count, r_create_time, r_update_time
      )
    values (#{rId,jdbcType=VARCHAR}, #{rGiftDate,jdbcType=VARCHAR}, #{rSid,jdbcType=VARCHAR}, 
      #{rCardNo,jdbcType=VARCHAR}, #{rCardName,jdbcType=VARCHAR}, #{rReOpenid,jdbcType=VARCHAR}, 
      #{rNumber,jdbcType=INTEGER}, #{rChainCode,jdbcType=VARCHAR}, #{rChainId,jdbcType=VARCHAR}, 
      #{rChainName,jdbcType=VARCHAR}, #{rTotalAmount,jdbcType=INTEGER}, #{rTotalCount,jdbcType=INTEGER}, 
      #{rPraiseCount,jdbcType=INTEGER}, #{rCreateTime,jdbcType=TIMESTAMP}, #{rUpdateTime,jdbcType=TIMESTAMP}
      )
  </insert>
  <insert id="insertSelective" parameterType="com.mybatis.entity.WxRankingFlow" >
    insert into wx_ranking_flow
    <trim prefix="(" suffix=")" suffixOverrides="," >
      <if test="rId != null" >
        r_id,
      </if>
      <if test="rGiftDate != null" >
        r_gift_date,
      </if>
      <if test="rSid != null" >
        r_sid,
      </if>
      <if test="rCardNo != null" >
        r_card_no,
      </if>
      <if test="rCardName != null" >
        r_card_name,
      </if>
      <if test="rReOpenid != null" >
        r_re_openid,
      </if>
      <if test="rNumber != null" >
        r_number,
      </if>
      <if test="rChainCode != null" >
        r_chain_code,
      </if>
      <if test="rChainId != null" >
        r_chain_id,
      </if>
      <if test="rChainName != null" >
        r_chain_name,
      </if>
      <if test="rTotalAmount != null" >
        r_total_amount,
      </if>
      <if test="rTotalCount != null" >
        r_total_count,
      </if>
      <if test="rPraiseCount != null" >
        r_praise_count,
      </if>
      <if test="rCreateTime != null" >
        r_create_time,
      </if>
      <if test="rUpdateTime != null" >
        r_update_time,
      </if>
    </trim>
    <trim prefix="values (" suffix=")" suffixOverrides="," >
      <if test="rId != null" >
        #{rId,jdbcType=VARCHAR},
      </if>
      <if test="rGiftDate != null" >
        #{rGiftDate,jdbcType=VARCHAR},
      </if>
      <if test="rSid != null" >
        #{rSid,jdbcType=VARCHAR},
      </if>
      <if test="rCardNo != null" >
        #{rCardNo,jdbcType=VARCHAR},
      </if>
      <if test="rCardName != null" >
        #{rCardName,jdbcType=VARCHAR},
      </if>
      <if test="rReOpenid != null" >
        #{rReOpenid,jdbcType=VARCHAR},
      </if>
      <if test="rNumber != null" >
        #{rNumber,jdbcType=INTEGER},
      </if>
      <if test="rChainCode != null" >
        #{rChainCode,jdbcType=VARCHAR},
      </if>
      <if test="rChainId != null" >
        #{rChainId,jdbcType=VARCHAR},
      </if>
      <if test="rChainName != null" >
        #{rChainName,jdbcType=VARCHAR},
      </if>
      <if test="rTotalAmount != null" >
        #{rTotalAmount,jdbcType=INTEGER},
      </if>
      <if test="rTotalCount != null" >
        #{rTotalCount,jdbcType=INTEGER},
      </if>
      <if test="rPraiseCount != null" >
        #{rPraiseCount,jdbcType=INTEGER},
      </if>
      <if test="rCreateTime != null" >
        #{rCreateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="rUpdateTime != null" >
        #{rUpdateTime,jdbcType=TIMESTAMP},
      </if>
    </trim>
  </insert>
  <select id="countByExample" parameterType="com.mybatis.entity.WxRankingFlowExample" resultType="java.lang.Integer" >
    select count(*) from wx_ranking_flow
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update wx_ranking_flow
    <set >
      <if test="record.rId != null" >
        r_id = #{record.rId,jdbcType=VARCHAR},
      </if>
      <if test="record.rGiftDate != null" >
        r_gift_date = #{record.rGiftDate,jdbcType=VARCHAR},
      </if>
      <if test="record.rSid != null" >
        r_sid = #{record.rSid,jdbcType=VARCHAR},
      </if>
      <if test="record.rCardNo != null" >
        r_card_no = #{record.rCardNo,jdbcType=VARCHAR},
      </if>
      <if test="record.rCardName != null" >
        r_card_name = #{record.rCardName,jdbcType=VARCHAR},
      </if>
      <if test="record.rReOpenid != null" >
        r_re_openid = #{record.rReOpenid,jdbcType=VARCHAR},
      </if>
      <if test="record.rNumber != null" >
        r_number = #{record.rNumber,jdbcType=INTEGER},
      </if>
      <if test="record.rChainCode != null" >
        r_chain_code = #{record.rChainCode,jdbcType=VARCHAR},
      </if>
      <if test="record.rChainId != null" >
        r_chain_id = #{record.rChainId,jdbcType=VARCHAR},
      </if>
      <if test="record.rChainName != null" >
        r_chain_name = #{record.rChainName,jdbcType=VARCHAR},
      </if>
      <if test="record.rTotalAmount != null" >
        r_total_amount = #{record.rTotalAmount,jdbcType=INTEGER},
      </if>
      <if test="record.rTotalCount != null" >
        r_total_count = #{record.rTotalCount,jdbcType=INTEGER},
      </if>
      <if test="record.rPraiseCount != null" >
        r_praise_count = #{record.rPraiseCount,jdbcType=INTEGER},
      </if>
      <if test="record.rCreateTime != null" >
        r_create_time = #{record.rCreateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="record.rUpdateTime != null" >
        r_update_time = #{record.rUpdateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByExample" parameterType="map" >
    update wx_ranking_flow
    set r_id = #{record.rId,jdbcType=VARCHAR},
      r_gift_date = #{record.rGiftDate,jdbcType=VARCHAR},
      r_sid = #{record.rSid,jdbcType=VARCHAR},
      r_card_no = #{record.rCardNo,jdbcType=VARCHAR},
      r_card_name = #{record.rCardName,jdbcType=VARCHAR},
      r_re_openid = #{record.rReOpenid,jdbcType=VARCHAR},
      r_number = #{record.rNumber,jdbcType=INTEGER},
      r_chain_code = #{record.rChainCode,jdbcType=VARCHAR},
      r_chain_id = #{record.rChainId,jdbcType=VARCHAR},
      r_chain_name = #{record.rChainName,jdbcType=VARCHAR},
      r_total_amount = #{record.rTotalAmount,jdbcType=INTEGER},
      r_total_count = #{record.rTotalCount,jdbcType=INTEGER},
      r_praise_count = #{record.rPraiseCount,jdbcType=INTEGER},
      r_create_time = #{record.rCreateTime,jdbcType=TIMESTAMP},
      r_update_time = #{record.rUpdateTime,jdbcType=TIMESTAMP}
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByPrimaryKeySelective" parameterType="com.mybatis.entity.WxRankingFlow" >
    update wx_ranking_flow
    <set >
      <if test="rGiftDate != null" >
        r_gift_date = #{rGiftDate,jdbcType=VARCHAR},
      </if>
      <if test="rSid != null" >
        r_sid = #{rSid,jdbcType=VARCHAR},
      </if>
      <if test="rCardNo != null" >
        r_card_no = #{rCardNo,jdbcType=VARCHAR},
      </if>
      <if test="rCardName != null" >
        r_card_name = #{rCardName,jdbcType=VARCHAR},
      </if>
      <if test="rReOpenid != null" >
        r_re_openid = #{rReOpenid,jdbcType=VARCHAR},
      </if>
      <if test="rNumber != null" >
        r_number = #{rNumber,jdbcType=INTEGER},
      </if>
      <if test="rChainCode != null" >
        r_chain_code = #{rChainCode,jdbcType=VARCHAR},
      </if>
      <if test="rChainId != null" >
        r_chain_id = #{rChainId,jdbcType=VARCHAR},
      </if>
      <if test="rChainName != null" >
        r_chain_name = #{rChainName,jdbcType=VARCHAR},
      </if>
      <if test="rTotalAmount != null" >
        r_total_amount = #{rTotalAmount,jdbcType=INTEGER},
      </if>
      <if test="rTotalCount != null" >
        r_total_count = #{rTotalCount,jdbcType=INTEGER},
      </if>
      <if test="rPraiseCount != null" >
        r_praise_count = #{rPraiseCount,jdbcType=INTEGER},
      </if>
      <if test="rCreateTime != null" >
        r_create_time = #{rCreateTime,jdbcType=TIMESTAMP},
      </if>
      <if test="rUpdateTime != null" >
        r_update_time = #{rUpdateTime,jdbcType=TIMESTAMP},
      </if>
    </set>
    where r_id = #{rId,jdbcType=VARCHAR}
  </update>
  <update id="updateByPrimaryKey" parameterType="com.mybatis.entity.WxRankingFlow" >
    update wx_ranking_flow
    set r_gift_date = #{rGiftDate,jdbcType=VARCHAR},
      r_sid = #{rSid,jdbcType=VARCHAR},
      r_card_no = #{rCardNo,jdbcType=VARCHAR},
      r_card_name = #{rCardName,jdbcType=VARCHAR},
      r_re_openid = #{rReOpenid,jdbcType=VARCHAR},
      r_number = #{rNumber,jdbcType=INTEGER},
      r_chain_code = #{rChainCode,jdbcType=VARCHAR},
      r_chain_id = #{rChainId,jdbcType=VARCHAR},
      r_chain_name = #{rChainName,jdbcType=VARCHAR},
      r_total_amount = #{rTotalAmount,jdbcType=INTEGER},
      r_total_count = #{rTotalCount,jdbcType=INTEGER},
      r_praise_count = #{rPraiseCount,jdbcType=INTEGER},
      r_create_time = #{rCreateTime,jdbcType=TIMESTAMP},
      r_update_time = #{rUpdateTime,jdbcType=TIMESTAMP}
    where r_id = #{rId,jdbcType=VARCHAR}
  </update>
  <select resultMap="BaseResultMap" parameterType="com.mybatis.entity.WxRankingFlowExample" id="selectByExampleWithRowbounds" >
    select
    <if test="distinct" >
      distinct
    </if>
    <include refid="Base_Column_List" />
    from wx_ranking_flow
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
    <if test="orderByClause != null" >
      order by ${orderByClause}
    </if>
  </select>
</mapper
MAC 系统和Windows 系统注意路径问题 。Windows是:\  MAC是:/
一. 生成器模板路径可以引用相关变量 如 ${basepackage}/${className}.java,根据该变量生成输出文件 二. 自动搜索某个目录所有模板文件,无需配置 三.代码生成器模板可以引用的相关变量 1. g.generateByTable("table_name") 方法可以引用的变量 table : cn.org.rapid_framework.generator.provider.db.table.model.Table 2. g.generateByClass(UserInfo.class) 方法可以引用的变量 clazz : cn.org.rapid_framework.generator.provider.java.model.JavaClass 3. g.generateBySql("select * from user_info where pwd=:pwd") 方法可以引用的变量 sql : cn.org.rapid_framework.generator.provider.db.sql.model.Sql 4.公共变量 env : 系统环境变量 System.getProperties() : 直接引用,没有前缀 generator.properties 文件中的所有属性,直接引用,没有前缀 gg : 模板控制变量, cn.org.rapid_framework.generator.GeneratorControl 四.每个模板有gg变量可以控制自身的自定义配置 (每一个模板都会创建新的gg实例) 如是否生成,是否覆盖目标文件,甚至是生成其它文件 ${gg.setIgnoreOutput(true)}: 如果为true则不生成输出文件 ${gg.generateFile(outputFile,content)} 在模板中生成其它文件 ${gg.getProperty(key,defaultValue)}: 得到proproty,如果没有找到,则返回默认值 ${gg.getInputProperty(key)}: 会弹出一个输入框,提示用户输入值 具体参考: http://code.google.com/p/rapid-framework/wiki/rapid_generator_gg 五.支持生成(gen)及删除操作(del),即生成的代码也可以很方便的删除 六. 自动删除模板扩展名: .ftl,.vm 举例: 如你有一个模板 SqlMap.xml.ftl 将变为 SqlMap.xml 所以你要生成ftl扩展名的文件,应该将文件名从 list.ftl => list.ftl.ftl 七. 模板自动include所有父目录的:macro.include文件,可以存放公共的macro 示例: 如你的模板为 com/project/UserDao.java, 将自动include: com/project/macro.include, com/macro.include, macro.include 八. generator.xml (或者generator.properties)配置文件 1.类似ant可以变量引用,引用环境变量使用${env.JAVA_HOME}, 引用System.getProperties()直接引用 2.自动替换generator.properties中的句号(.)为反斜杠,设置key为key+"_dir"后缀 示例: pkg=com.company => pkg_dir=com/company 九.自动拷贝二进制文件至输出目录 如模板目录下的 zip,rar,doc文件将会自动拷贝至输出目录,不会破坏文件格式 (通过扩展名自动识别) 十. 数据库表配置,用于自定义生成器模板引用的table变量,配置文件必须存放在classpath: generator_config/table/table_name.xml (该文件生成器可以生成,自己再自定义修改)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值