当前仓库属于暂停状态,部分功能使用受限,详情请查阅 仓库状态说明
1 Star 0 Fork 120

mayday / mybatis.generator
暂停

forked from 匆匆里 / mybatis.generator 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
Apache-2.0

mybatis.generator

2017-09-01 更新 1.9.9.5-SNAPSHOT

  1. kvmap 扩展 kvmap= (false|true|list|set) 返回结构为 Map<K,V> Map<K,List> Map<K,Set> 其中 list set 方式为新增

  2. 增加对TDDL 参数支持 如 /TDDL xxxx/

  3. 分页支持增强: 增加 pagingCntType 类型 (paging|optimize|pagingExtCnt|pagingCustom)

    • paging 默认类型,跟之前保持一致
    • optimize 增强 解决分页到最后时回表导致查询慢 sql提速方案详见下面例子
       select 
           *
       FROM  
           tabA
        where aa = ?
        limit 100000010  -- 如果tabA表中字段很长会导致后面查询很慢
       -- 改进后sql为
      select * from
       (<optimizePaging>
          select 
            id
          FROM  
            tabA
          where aa = ?
          limit 100000010
         </optimizePaging>
        ) a 
        join 
          tabA t 
        on a.id=t.id 
     --- optimizePaging 标签内SQL 单独生成一个CountSQL
    • pagingExtCnt 对distinct支持
    select 
        DISTINCT name,code 
    FROM  
        tabA
     where aa = ?
    -- 此种分页会自动生成 将此SQL 括起来的求总数 sql
    • pagingCustom 自定义分页Count operation (万能型)

更新

  1. 批量插入
<!-- insertBatch 因为是插入,所有要求必须以 insert开头,update也是如此要求 -->
<operation name="insertBatch"  remark="批量插入结构化面试能力项">
        INSERT INTO RC_STRUCTURED_INTERVIEW_ABILITY_ITEM(
             CODE
            ,NAME
            ,TYPE
            ,STATUS
            ,CREATOR
            ,SYNONYM
            ,MODIFIER
            ,IS_DELETED
            ,DESCRIPTION
            ,GMT_CREATE
            ,GMT_MODIFIED
        )VALUES
<!-- foreach javaType 主要解决自定义类型的批量掺入, 如不指定类型 需要在 operation 中设置 paramtype="objectList"  会使用 List<DO> 作为查询条件 -->
        <foreach collection="list" javatype="com.alibaba.hr.model.BatchAbilityItemModel" item="item" separator=",">
        (
              #{item.code,jdbcType=VARCHAR}
            , #{item.name,jdbcType=VARCHAR}
            , #{item.type,jdbcType=VARCHAR}
            , #{item.status,jdbcType=VARCHAR}
            , #{item.creator,jdbcType=VARCHAR}
            , #{item.synonymStr,jdbcType=VARCHAR}
            , #{item.modifier,jdbcType=VARCHAR}
            , 'N'
            , #{item.description,jdbcType=VARCHAR}
            , now()
            , now()
        )
        </foreach>
    </operation>

更新 2017-3-14

版本升级为1.9.0-SNAPSHOT

  1. 增加 DBPreCheckMapper,可以在通过在Checkpreload 调用可以在项目启动时检查表结构变更是否完成。
  2. 优化java类中import输出顺序问题导致mac与Windows下不一致问题

更新 2016-11-05

  1. foreach 增加javatype支持,可以传入自定义java对象进行 in查询,增强原来只支持基本类型的List
  2. operation 增加 kvmap="true" 支持 可以自动从返回List结果转为 Map<K,V> 类型,注意不是将字段作为key而是将字段值作为Key

更新 2016-05-25

  1. 支持扩展条件

<operation name="xx" paramtype="xx" remark="xx">
    <extraparams>
        <param name="order" javatype="com.alibaba.hr.common.util.enums.common.YesOrNoEnum"/>
    </extraparams>
</operation>

更新 2016-03-27

  1. 支持唯一约束自动生成SQL (表初始化时)
  2. 支持软删除

更新 2016-03-23 (修复)

  1. DAO参数排序
  2. DAO参数去重

更新 2015-12-20

增加 ? 支持 但不会指定 jdbcType类型

更新 2015-12-19

增加 OB数据源支持

目前支持

  1. 分页
  2. mysql,ob
  3. 自定义ResultMap
  4. ...

简介

mybatis.generator 源码

  1. 解决问题 mybatis.generator 后续简称 dalgen,解决mybatis代码自动生成的缺失.
  2. 对比其他代码生成工具
    • mybatis-generator-maven-plugin 目前正在使用的代码生成工具,只能根据指定表结构反向生成do,mapper,mapper.xml且生成大量mybatis动态sql.
    • dalgen 除能根据指定表结构生成 do,mapper,mapper.xml外,还能根据自定义sql 自动生成对应mapper接口中的方法等

能做什么

支持MySQL

支持分表

  • 具体参考 config.xml

初始化生成的方法有

  • insert,update,deleteByPrimary,getByPrimary四个简单地方法

其他自定义SQL

  • 写在 operation中,执行 mvn mybatis:gen 后会自动帮您生成相关数据

基本动态sql支持

自定义参数:

  • 指定 paramtype=primitive 会根据 sql中的 "#{...}" or ? 生成原生的参数.
  • 指定 paramtype=object 参数为 DO 对象
  • 其他参数类型不再支持,支持多了容易给维护带来困难
  • 支持扩展条件,默认参数是根据sql中#{}或?产生,有时候会有额外用于判断的参数通过扩展生成出来

<operation name="xx" paramtype="xx" remark="xx">
<extraparams>
    <param name="order" javatype="com.alibaba.hr.common.util.enums.common.YesOrNoEnum"/>
</extraparams>

定义返回结果:

  • 返回结果 可以指定 resultmap,resuttype
  • resultmap 非变更类的 默认返回结果,不需要指定
  • reulttype 自定义返回类型,可以指定Map(需要写为全类) 原生类(String,Long等)大小写敏感
  • 自定义resultmap, 有时候返回类型比较特殊,那么可以自己定义resultmap, dalgen 会帮您生成对应的类

其他

  • 可以自由摸索

暂不能做什么

暂不支持Oracle,如有需要单独通知我,bangis.wangdf@alibaba-inc.com

不会支持什么

在 sql模板中不提供 mybatis特有的<sql>标签,避免复杂动态sql产生

如何使用

pom中添加依赖

<plugin>
    <groupId>org.bgdf.generator</groupId>
    <artifactId>mybatis-maven-plugin</artifactId>
    <version>${mybatis-maven-plugin_version}</version>
    <!-- 可选 不填写 使用默认路径-->
    <configuration>
        <!-- 代码输出路径 -->
        <outputDirectory>src</outputDirectory>
        <config>dalgen/config/config.xml</config>
        
        <!-- <copyTemplate>true</copyTemplate>  -->
        <!-- <templateDirectory>dalgen/templates</templateDirectory> -->
        <!-- 自定义模板文件 -->
        <templateExtDirectory>dalgen/ext</templateExtDirectory>
    </configuration>
</plugin>
  • 执行 mvn mybatis:gen 首先会初始化配置,减少了一步自己copy 配置文件的麻烦
<?xml version="1.0" encoding="UTF-8"?>
<!--config.xml 支持分页,支持OB,支持参数简写为 ?-->

<!-- ============================================================== -->
<!-- Master configuration file for auto-generation of iPaycore dal. -->
<!-- ============================================================== -->

<config>
    <!-- ========================================================== -->
    <!-- The typemap("Type Map") maps from one java type to another -->
    <!-- java type. If you feel the original sql data type to java -->
    <!-- type mapping is not satisfactory, you can use typemap to -->
    <!-- convert it to a more appropriate one. -->
    <!-- ========================================================== -->
    <typemap from="java.sql.Date" to="java.util.Date"/>
    <typemap from="java.sql.Time" to="java.util.Date"/>
    <typemap from="java.sql.Timestamp" to="java.util.Date"/>
    <typemap from="java.math.BigDecimal" to="Long"/>
    <typemap from="byte" to="int"/>
    <typemap from="short" to="int"/>

    <!-- ========================================================== -->
    <!-- datasource config  可以配置多个-->
    <!-- ========================================================== -->
    <database name="fbi" type="tddl-mysql">
        <property name="appName" value="CIO_FBI_APP"/>
        <property name="dbGroupKey" value="CIO_FBI_GROUP"/>
    </database>

    <!--ob 配置 执行失败则需要 替换${java_home}/jre/lib/security/ 下面的local_policy.jar和US_export_policy.jar-->
    <database name="fporgassetcenter" type="ob">
        <property name="url" value="http://obconsole.test.alibaba-inc.com/ob-config/config.co?dataId=daily_052"/>
    </database>

    <!-- ========project.name pom.xml中的值========================= -->
    <!--<package value="com.oschina.${project.name}.common.dal.${database.name}.auto"/>-->
    <package value="com.alibaba.recruit.datacenter.dal.${database.name}"/>

    <!-- ========================================================== -->
    <!-- 省略前置 支持多个 -->
    <tablePrefix value="dc_bg"/><!--长的放前面-->
    <tablePrefix value="dc"/>
    <tablePath value="${database.name}Tables/"/>
    <!--分库分表规则  分表后缀 支持多个-->
    <splitTableSuffix value="_000"/>

</config>

table.xml 例子

*首次执行输出DC_BG_RISK_SCAN 后DC_BG_RISK_SCAN.xml会自动生成,您仅需要添加自己的sql即可

<!DOCTYPE table SYSTEM "../table-config-1.1.dtd">
<!--DC_BG_RISK_SCAN.xml-->
<!-- sqlname逻辑表,用于生成对象   physicalName物理表,用于从数据中获取数据 -->
<table sqlname="DC_BG_RISK_SCAN" physicalName="DC_BG_RISK_SCAN">
    <!--  特殊字符说明  &lt;&gt;   <> -->
    <operation name="insert" paramtype="object" remark="插入表:DC_BG_RISK_SCAN">
        <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
            SELECT
            LAST_INSERT_ID()
        </selectKey>
        INSERT INTO DC_BG_RISK_SCAN(
            ID
            ,NAME
            ,RISK
            ,DETAIL
            ,EDU_INFO
            ,ID_CARD_NO
            ,DETAIL_URL
            ,GMT_CREATE
            ,GMT_MODIFIED
        )VALUES(
             #{id,jdbcType=BIGINT}
            , #{name,jdbcType=VARCHAR}
            , #{risk,jdbcType=CHAR}
            , #{detail,jdbcType=VARCHAR}
            , #{eduInfo,jdbcType=VARCHAR}
            , #{idCardNo,jdbcType=VARCHAR}
            , #{detailUrl,jdbcType=VARCHAR}
            , #{gmtCreate,jdbcType=TIMESTAMP}
            , #{gmtModified,jdbcType=TIMESTAMP}
        )
    </operation>

    <operation name="update" paramtype="object" remark="更新表:DC_BG_RISK_SCAN">
        UPDATE DC_BG_RISK_SCAN
        SET
            ID              = #{id,jdbcType=BIGINT}
            ,NAME            = #{name,jdbcType=VARCHAR}
            ,RISK            = #{risk,jdbcType=CHAR}
            ,DETAIL          = #{detail,jdbcType=VARCHAR}
            ,EDU_INFO        = #{eduInfo,jdbcType=VARCHAR}
            ,ID_CARD_NO      = #{idCardNo,jdbcType=VARCHAR}
            ,DETAIL_URL      = #{detailUrl,jdbcType=VARCHAR}
            ,GMT_CREATE      = #{gmtCreate,jdbcType=TIMESTAMP}
            ,GMT_MODIFIED    = #{gmtModified,jdbcType=TIMESTAMP}
        WHERE
            ID              = #{id,jdbcType=BIGINT}
    </operation>

    <operation name="deleteByPrimary" multiplicity="one" remark="根据主键删除数据:DC_BG_RISK_SCAN">
        DELETE FROM
            DC_BG_RISK_SCAN
        WHERE
            ID = #{id,jdbcType=BIGINT}
    </operation>

    <operation name="getByPrimary" multiplicity="one"  remark="根据主键获取数据:DC_BG_RISK_SCAN">
        SELECT *
        FROM DC_BG_RISK_SCAN
        WHERE
            ID = #{id,jdbcType=BIGINT}
    </operation>

    <!--自定义resultMap-->
    <resultmap name="myResultMap" type="MyResult">
        <column name="name" javatype="String"/>
        <column name="risk" javatype="String"/>
    </resultmap>

    <!-- idCardNoXX 自定义参数,需要指定类型,可以通过 jdbcType 也可以通过 javaType -->
    <operation name="getMyResultMap" resultmap="myResultMap" remark="自定义ResultMap">
        select
            name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        or
        id_card_no=#{idCardNoXX,jdbcType=VARCHAR}
        limit 1
    </operation>

    <!-- idCardNoXX 自定义参数,需要指定类型,可以通过 jdbcType 也可以通过 javaType -->
    <operation name="getListParams" resultmap="myResultMap" remark="foreach支持">
        select
        name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>
        limit 1
    </operation>

    <!-- idCardNoXX 自定义参数,需要指定类型,可以通过 jdbcType 也可以通过 javaType -->
    <operation name="getListParamsMany" multiplicity="many" resultmap="myResultMap" remark="foreach支持 many">
        select
        name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>
    </operation>
</table>

生成结果

RiskScanDOMapper.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.alibaba.recruit.datacenter.risk.dal.mapper.RiskScanDOMapper">
    <!-- 自动生成,请修改 DC_BG_RISK_SCAN.xml -->
    <resultMap id="BaseResultMap"  type="com.alibaba.recruit.datacenter.risk.dal.dataobject.RiskScanDO">
        <id column="ID" property="id" jdbcType="BIGINT" javaType="Long"/>
        <result column="NAME" property="name" jdbcType="VARCHAR" javaType="String"/>
        <result column="RISK" property="risk" jdbcType="CHAR" javaType="String"/>
        <result column="DETAIL" property="detail" jdbcType="VARCHAR" javaType="String"/>
        <result column="EDU_INFO" property="eduInfo" jdbcType="VARCHAR" javaType="String"/>
        <result column="ID_CARD_NO" property="idCardNo" jdbcType="VARCHAR" javaType="String"/>
        <result column="DETAIL_URL" property="detailUrl" jdbcType="VARCHAR" javaType="String"/>
        <result column="GMT_CREATE" property="gmtCreate" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
        <result column="GMT_MODIFIED" property="gmtModified" jdbcType="TIMESTAMP" javaType="java.util.Date"/>
    </resultMap>

    <resultMap id="myResultMap"  type="com.alibaba.recruit.datacenter.risk.dal.resultmap.MyResult">
        <result column="NAME" property="name" jdbcType="VARCHAR" javaType="String"/>
        <result column="RISK" property="risk" jdbcType="CHAR" javaType="String"/>
    </resultMap>

    <sql id="Base_Column_List">
        ID,NAME,RISK,DETAIL,EDU_INFO,ID_CARD_NO,DETAIL_URL,GMT_CREATE,GMT_MODIFIED
    </sql>


    <!--插入表:DC_BG_RISK_SCAN-->
    <insert id="insert" >
        <selectKey resultType="java.lang.Long" keyProperty="id" order="AFTER">
            SELECT
            LAST_INSERT_ID()
        </selectKey>
        INSERT INTO DC_BG_RISK_SCAN(
            ID
            ,NAME
            ,RISK
            ,DETAIL
            ,EDU_INFO
            ,ID_CARD_NO
            ,DETAIL_URL
            ,GMT_CREATE
            ,GMT_MODIFIED
        )VALUES(
             #{id,jdbcType=BIGINT}
            , #{name,jdbcType=VARCHAR}
            , #{risk,jdbcType=CHAR}
            , #{detail,jdbcType=VARCHAR}
            , #{eduInfo,jdbcType=VARCHAR}
            , #{idCardNo,jdbcType=VARCHAR}
            , #{detailUrl,jdbcType=VARCHAR}
            , #{gmtCreate,jdbcType=TIMESTAMP}
            , #{gmtModified,jdbcType=TIMESTAMP}
        )
    </insert>

    <!--更新表:DC_BG_RISK_SCAN-->
    <update id="update" >
        UPDATE /*MS-AUTODALGEN-DC-BG-RISK-SCAN-UPDATE*/ DC_BG_RISK_SCAN
        SET
            ID              = #{id,jdbcType=BIGINT}
            ,NAME            = #{name,jdbcType=VARCHAR}
            ,RISK            = #{risk,jdbcType=CHAR}
            ,DETAIL          = #{detail,jdbcType=VARCHAR}
            ,EDU_INFO        = #{eduInfo,jdbcType=VARCHAR}
            ,ID_CARD_NO      = #{idCardNo,jdbcType=VARCHAR}
            ,DETAIL_URL      = #{detailUrl,jdbcType=VARCHAR}
            ,GMT_CREATE      = #{gmtCreate,jdbcType=TIMESTAMP}
            ,GMT_MODIFIED    = #{gmtModified,jdbcType=TIMESTAMP}
        WHERE
            ID              = #{id,jdbcType=BIGINT}
    </update>

    <!--根据主键删除数据:DC_BG_RISK_SCAN-->
    <delete id="deleteByPrimary" >
        DELETE /*MS-AUTODALGEN-DC-BG-RISK-SCAN-DELETEBYPRIMARY*/ FROM
            DC_BG_RISK_SCAN
        WHERE
            ID = #{id,jdbcType=BIGINT}
    </delete>

    <!--根据主键获取数据:DC_BG_RISK_SCAN-->
    <select id="getByPrimary" resultMap="BaseResultMap">
        SELECT /*MS-AUTODALGEN-DC-BG-RISK-SCAN-GETBYPRIMARY*/  <include refid="Base_Column_List" />
        FROM DC_BG_RISK_SCAN
        WHERE
            ID = #{id,jdbcType=BIGINT}
    </select>

    <!--自定义ResultMap-->
    <select id="getMyResultMap" resultMap="myResultMap">
        select
            name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        or
        id_card_no=#{idCardNoXX,jdbcType=VARCHAR}
        limit 1
    </select>

    <!--foreach支持-->
    <select id="getListParams" resultMap="myResultMap">
        select
        name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>
        limit 1
    </select>

    <!--foreach支持 many-->
    <select id="getListParamsMany" resultMap="myResultMap">
        select
        name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>
    </select>
</mapper>
package com.alibaba.recruit.datacenter.risk.dal.mapper;

import com.alibaba.recruit.datacenter.risk.dal.dataobject.RiskScanDO;
import com.alibaba.recruit.datacenter.risk.dal.resultmap.MyResult;
import java.util.List;

/**
 *The Table DC_BG_RISK_SCAN.
 *风险扫描
 */
public interface RiskScanDOMapper{

    /**
     *desc:插入表:DC_BG_RISK_SCAN.<br/>
     *descSql =  SELECT LAST_INSERT_ID() INSERT INTO DC_BG_RISK_SCAN( ID ,NAME ,RISK ,DETAIL ,EDU_INFO ,ID_CARD_NO ,DETAIL_URL ,GMT_CREATE ,GMT_MODIFIED )VALUES( #{id,jdbcType=BIGINT} , #{name,jdbcType=VARCHAR} , #{risk,jdbcType=CHAR} , #{detail,jdbcType=VARCHAR} , #{eduInfo,jdbcType=VARCHAR} , #{idCardNo,jdbcType=VARCHAR} , #{detailUrl,jdbcType=VARCHAR} , #{gmtCreate,jdbcType=TIMESTAMP} , #{gmtModified,jdbcType=TIMESTAMP} )
     *@param RiskScanDO RiskScanDO
     *@return Long
     */
    Long insert(entity RiskScanDO);
    /**
     *desc:更新表:DC_BG_RISK_SCAN.<br/>
     *descSql =  UPDATE DC_BG_RISK_SCAN SET ID = #{id,jdbcType=BIGINT} ,NAME = #{name,jdbcType=VARCHAR} ,RISK = #{risk,jdbcType=CHAR} ,DETAIL = #{detail,jdbcType=VARCHAR} ,EDU_INFO = #{eduInfo,jdbcType=VARCHAR} ,ID_CARD_NO = #{idCardNo,jdbcType=VARCHAR} ,DETAIL_URL = #{detailUrl,jdbcType=VARCHAR} ,GMT_CREATE = #{gmtCreate,jdbcType=TIMESTAMP} ,GMT_MODIFIED = #{gmtModified,jdbcType=TIMESTAMP} WHERE ID = #{id,jdbcType=BIGINT}
     *@param RiskScanDO RiskScanDO
     *@return Long
     */
    Long update(entity RiskScanDO);
    /**
     *desc:根据主键删除数据:DC_BG_RISK_SCAN.<br/>
     *descSql =  DELETE FROM DC_BG_RISK_SCAN WHERE ID = #{id,jdbcType=BIGINT}
     *@param id id
     *@return Long
     */
    Long deleteByPrimary(Long id);
    /**
     *desc:根据主键获取数据:DC_BG_RISK_SCAN.<br/>
     *descSql =  SELECT *FROM DC_BG_RISK_SCAN WHERE ID = #{id,jdbcType=BIGINT}
     *@param id id
     *@return RiskScanDO
     */
    RiskScanDO getByPrimary(Long id);
    /**
     *desc:自定义ResultMap.<br/>
     *descSql =  select name,risk from DC_BG_RISK_SCAN where id_card_no=#{idCardNo} or id_card_no=#{idCardNoXX,jdbcType=VARCHAR} limit 1
     *@param idCardNo idCardNo
     *@param idCardNoXX idCardNoXX
     *@return MyResult
     */
    MyResult getMyResultMap(String idCardNo,String idCardNoXX);
    /**
     *desc:foreach支持.<br/>
     *descSql =  select name,risk from DC_BG_RISK_SCAN where id_card_no=#{idCardNo} and name in #{name,jdbcType=VARCHAR} limit 1
     *@param idCardNo idCardNo
     *@param names names
     *@return MyResult
     */
    MyResult getListParams(String idCardNo,List<String> names);
    /**
     *desc:foreach支持 many.<br/>
     *descSql =  select name,risk from DC_BG_RISK_SCAN where id_card_no=#{idCardNo} and name in #{name,jdbcType=VARCHAR} 
     *@param idCardNo idCardNo
     *@param names names
     *@return List<MyResult>
     */
    List<MyResult> getListParamsMany(String idCardNo,List<String> names);
}

增加分页支持

multiplicity="paging" --标记为此方法需要走分页查询
paging="QueryRisk"    --分页查询参数类名称
                      --自动生成DAO类,通过Spring 自动扫描方法注入,不提供xml配置项目生成了.
                      --DOMapper接口与DAO类区别在于对分页的支持
    <operation name="getListParamsPage" multiplicity="paging" paging="QueryRisk" resultmap="myResultMap" remark="foreach支持 many">
        select
        name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>
        order by gmt_modified desc
    </operation>

Mapper.xml结果
    <!--foreach支持 many pageCount-->
    <select id="getListParamsPageCount"  resultType="int">
        SELECT COUNT(*) AS total FROM
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>

    </select>
    <!--foreach支持 many pageResult-->
    <select id="getListParamsPageResult"  resultMap="myResultMap">
        select
        name,risk
        from
        DC_BG_RISK_SCAN
        where
        id_card_no=#{idCardNo}
        and
        name in
        <foreach collection="names" item="name" index="index" open="(" close=")" separator=",">
            #{name,jdbcType=VARCHAR}
        </foreach>
        order by gmt_modified desc
        limit #{startRow},#{limit}
    </select>

DOMapper.java
   /**
     * desc:foreach支持 many.<br/>
     * descSql =  select name,risk from DC_BG_RISK_SCAN where id_card_no=#{idCardNo} and name in #{name,jdbcType=VARCHAR} order by gmt_modified desc
     * @param queryRisk queryRisk
     * @return int
     */
    int getListParamsPageCount(QueryRiskPage queryRisk);
    /**
     * desc:foreach支持 many.<br/>
     * descSql =  select name,risk from DC_BG_RISK_SCAN where id_card_no=#{idCardNo} and name in #{name,jdbcType=VARCHAR} order by gmt_modified desc
     * @param queryRisk queryRisk
     * @return List<MyResult>
     */
    List<MyResult> getListParamsPageResult(QueryRiskPage queryRisk);

DAO.java
    /**
     * desc:foreach支持 many.<br/>
     * descSql =  select name,risk from DC_BG_RISK_SCAN where id_card_no=#{idCardNo} and name in #{name,jdbcType=VARCHAR} order by gmt_modified desc
     * @param queryRisk queryRisk
     * @return QueryRiskPage
     */
    public QueryRiskPage getListParamsPage(QueryRiskPage queryRisk){
        int total = riskScanDOMapper.getListParamsPageCount(queryRisk);
        if(total>0){
            queryRisk.setDatas(riskScanDOMapper.getListParamsPageResult(queryRisk));
        }
        queryRisk.setTotal(total);
        return queryRisk;
    }
如需分页会自动创建分页类 BasePage.java
Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: You must give any other recipients of the Work or Derivative Works a copy of this License; and You must cause any modified files to carry prominent notices stating that You changed the files; and You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "{}" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2017 bangis and 匆匆里 Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

简介

mybatis代码生成器 优化版 展开 收起
Java
Apache-2.0
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
Java
1
https://gitee.com/chrismayday/mybatis.generator.git
git@gitee.com:chrismayday/mybatis.generator.git
chrismayday
mybatis.generator
mybatis.generator
master

搜索帮助