{"id":15019209,"url":"https://github.com/itfsw/mybatis-generator-plugin","last_synced_at":"2025-05-14T14:07:33.438Z","repository":{"id":15456605,"uuid":"78185171","full_name":"itfsw/mybatis-generator-plugin","owner":"itfsw","description":"Mybatis Generator 代码生成插件拓展，增加：查询单条数据插件（SelectOneByExamplePlugin）、MySQL分页插件（LimitPlugin）、数据Model链式构建插件（ModelBuilderPlugin）、Example Criteria 增强插件（ExampleEnhancedPlugin）、Example 目标包修改插件（ExampleTargetPlugin）、批量插入插件（BatchInsertPlugin）、逻辑删除插件（LogicalDeletePlugin）、数据Model属性对应Column获取插件（ModelColumnPlugin）、存在即更新（UpsertPlugin）、Selective选择插入更新增强插件（SelectiveEnhancedPlugin）、Table增加前缀插件（TableSuffixPlugin）、自定义注释插件（CommentPlugin）、增量插件（IncrementsPlugin）、查询结果选择性返回插件（SelectSelectivePlugin）、乐观锁插件（OptimisticLockerPlugin）、LombokPlugin等拓展。","archived":false,"fork":false,"pushed_at":"2024-03-19T06:22:35.000Z","size":1187,"stargazers_count":1365,"open_issues_count":44,"forks_count":400,"subscribers_count":65,"default_branch":"master","last_synced_at":"2025-04-11T06:13:37.641Z","etag":null,"topics":["batchinsert","limit","lombok","mybatis","mybatis-generator","mysql","plugin","selectone","upsert"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/itfsw.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-01-06T07:35:23.000Z","updated_at":"2025-04-07T02:27:06.000Z","dependencies_parsed_at":"2023-12-29T03:31:41.406Z","dependency_job_id":"5368d7f3-1172-442d-8746-f23b6245bada","html_url":"https://github.com/itfsw/mybatis-generator-plugin","commit_stats":null,"previous_names":[],"tags_count":59,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itfsw%2Fmybatis-generator-plugin","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itfsw%2Fmybatis-generator-plugin/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itfsw%2Fmybatis-generator-plugin/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/itfsw%2Fmybatis-generator-plugin/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/itfsw","download_url":"https://codeload.github.com/itfsw/mybatis-generator-plugin/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254159194,"owners_count":22024558,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["batchinsert","limit","lombok","mybatis","mybatis-generator","mysql","plugin","selectone","upsert"],"created_at":"2024-09-24T19:53:10.083Z","updated_at":"2025-05-14T14:07:33.416Z","avatar_url":"https://github.com/itfsw.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 这是 MyBatis Generator 插件的拓展插件包  \n应该说使用Mybatis就一定离不开[MyBatis Generator](https://github.com/mybatis/generator)这款代码生成插件，而这款插件自身还提供了插件拓展功能用于强化插件本身，官方已经提供了一些[拓展插件](http://www.mybatis.org/generator/reference/plugins.html)，本项目的目的也是通过该插件机制来强化Mybatis Generator本身，方便和减少我们平时的代码开发量。  \n\u003e因为插件是本人兴之所至所临时发布的项目（本人已近三年未做JAVA开发，代码水平请大家见谅），但基本插件都是在实际项目中经过检验的请大家放心使用，但因为项目目前主要数据库为MySQL，Mybatis实现使用Mapper.xml方式，所以代码生成时对于其他数据库和注解方式的支持未予考虑，请大家见谅。    \n  \n\u003eV1.3.x版本的测试基准基于mybatis-3.5.0，同时向下兼容V3.4.0(某些插件需要context节点配置mybatis版本信息[[issues#70](https://github.com/itfsw/mybatis-generator-plugin/issues/70)])。老版本参见分支[V1.2.x](https://github.com/itfsw/mybatis-generator-plugin/tree/V1.2)；  \n```xml\n\u003ccontext\u003e\n    \u003c!-- \n        解决 批量插入插件（BatchInsertPlugin）在mybatis3.5.0以下版本无法返回自增主键的问题\n        指定mybatis版本，让插件指定您所使用的mybatis版本生成对应代码\n     --\u003e\n    \u003cproperty name=\"mybatisVersion\" value=\"3.4.0\"/\u003e\n\u003c/context\u003e\n```\n\n---------------------------------------\n插件列表：  \n* [查询单条数据插件（SelectOneByExamplePlugin）](#1-查询单条数据插件)\n* [MySQL分页插件（LimitPlugin）](#2-mysql分页插件)\n* [数据Model链式构建插件（ModelBuilderPlugin）](#3-数据model链式构建插件)\n* [Example Criteria 增强插件（ExampleEnhancedPlugin）](#4-example-增强插件exampleandiforderby)\n* [Example 目标包修改插件（ExampleTargetPlugin）](#5-example-目标包修改插件)\n* [批量插入插件（BatchInsertPlugin）](#6-批量插入插件)\n* [逻辑删除插件（LogicalDeletePlugin）](#7-逻辑删除插件)\n* [数据Model属性对应Column获取插件（ModelColumnPlugin）](#8-数据model属性对应column获取插件)\n* [存在即更新插件（UpsertPlugin）](#9-存在即更新插件)\n* [Selective选择插入更新增强插件（SelectiveEnhancedPlugin）](#10-selective选择插入更新增强插件)\n* [~~Table增加前缀插件（TablePrefixPlugin）~~](#11-table增加前缀插件)\n* [~~Table重命名插件（TableRenamePlugin）~~](#12-table重命名插件)\n* [自定义注释插件（CommentPlugin）](#13-自定义注释插件)\n* [~~增量插件（IncrementsPlugin）~~](#14-增量插件)\n* [查询结果选择性返回插件（SelectSelectivePlugin）](#15-查询结果选择性返回插件)\n* [~~官方ConstructorBased配置BUG临时修正插件（ConstructorBasedBugFixPlugin）~~](#16-官方constructorbased配置bug临时修正插件)\n* [乐观锁插件（OptimisticLockerPlugin）](#17-乐观锁插件)\n* [表重命名配置插件（TableRenameConfigurationPlugin）](#18-表重命名配置插件)\n* [Lombok插件（LombokPlugin）](#19-Lombok插件)\n* [数据ModelCloneable插件（ModelCloneablePlugin）](#20-数据ModelCloneable插件)\n* [状态枚举生成插件（EnumTypeStatusPlugin）](#21-状态枚举生成插件)\n* [增量插件（IncrementPlugin）](#22-增量插件)\n* [Mapper注解插件（MapperAnnotationPlugin）](#23-Mapper注解插件)\n\n---------------------------------------\nMaven引用：  \n```xml\n\u003cdependency\u003e\n  \u003cgroupId\u003ecom.itfsw\u003c/groupId\u003e\n  \u003cartifactId\u003emybatis-generator-plugin\u003c/artifactId\u003e\n  \u003cversion\u003e1.3.10\u003c/version\u003e\n\u003c/dependency\u003e\n```\n---------------------------------------\nMyBatis Generator 参考配置（插件依赖应该配置在mybatis-generator-maven-plugin插件依赖中[[issues#6]](https://github.com/itfsw/mybatis-generator-plugin/issues/6)）\n```xml\n\u003c!-- mybatis-generator 自动代码插件 --\u003e\n\u003cplugin\u003e\n    \u003cgroupId\u003eorg.mybatis.generator\u003c/groupId\u003e\n    \u003cartifactId\u003emybatis-generator-maven-plugin\u003c/artifactId\u003e\n    \u003cversion\u003e1.3.7\u003c/version\u003e\n    \u003cconfiguration\u003e\n        \u003c!-- 配置文件 --\u003e\n        \u003cconfigurationFile\u003esrc/main/resources/mybatis-generator.xml\u003c/configurationFile\u003e\n        \u003c!-- 允许移动和修改 --\u003e\n        \u003cverbose\u003etrue\u003c/verbose\u003e\n        \u003coverwrite\u003etrue\u003c/overwrite\u003e\n    \u003c/configuration\u003e\n    \u003cdependencies\u003e\n        \u003c!-- jdbc 依赖 --\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003emysql\u003c/groupId\u003e\n            \u003cartifactId\u003emysql-connector-java\u003c/artifactId\u003e\n            \u003cversion\u003e${mysql.driver.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003ecom.itfsw\u003c/groupId\u003e\n            \u003cartifactId\u003emybatis-generator-plugin\u003c/artifactId\u003e\n            \u003cversion\u003e${mybatis.generator.plugin.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n    \u003c/dependencies\u003e\n\u003c/plugin\u003e\n```\n---------------------------------------\ngradle集成[[issues#41]](https://github.com/itfsw/mybatis-generator-plugin/issues/41)），感谢[masa-kunikata](https://github.com/masa-kunikata)提供的脚本。\n```gradle\n// https://gist.github.com/masa-kunikata/daaf0f51a8ab9b808f61805407e1654c\nbuildscript {\n    repositories {\n        maven { url \"https://plugins.gradle.org/m2/\" }\n    }\n    dependencies {\n        classpath \"gradle.plugin.com.arenagod.gradle:mybatis-generator-plugin:1.4\"\n    }\n}\n\napply plugin: 'java-library'\napply plugin: \"com.arenagod.gradle.MybatisGenerator\"\napply plugin: 'eclipse'\n\nsourceCompatibility = 1.8\ntargetCompatibility = 1.8\n\n\ndef mybatisGeneratorCore = 'org.mybatis.generator:mybatis-generator-core:1.3.7'\ndef itfswMybatisGeneratorPlugin = 'com.itfsw:mybatis-generator-plugin:1.3.9'\n\nmybatisGenerator {\n  verbose = false\n  configFile = \"config/mybatisGenerator/generatorConfig.xml\"\n\n  dependencies {\n    mybatisGenerator project(':')\n    mybatisGenerator itfswMybatisGeneratorPlugin\n    mybatisGenerator mybatisGeneratorCore\n  }\n}\n\nrepositories {\n    mavenCentral()\n}\n\ndependencies {\n    compile mybatisGeneratorCore\n    compile itfswMybatisGeneratorPlugin\n    testCompile 'junit:junit:4.12'\n}\n\ndef defaultEncoding = 'UTF-8'\n\ncompileJava {\n    options.encoding = defaultEncoding\n}\ncompileTestJava {\n    options.encoding = defaultEncoding\n}\n```\n---------------------------------------\n### 1. 查询单条数据插件\n对应表Mapper接口增加了方法  \n插件：\n```xml\n\u003c!-- 查询单条数据插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.SelectOneByExamplePlugin\"/\u003e\n```\n使用：  \n```java\npublic interface TbMapper {    \n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    Tb selectOneByExample(TbExample example);\n    \n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    // Model WithBLOBs 时才有\n    TbWithBLOBs selectOneByExampleWithBLOBs(TbExample example);\n}\n```\n### 2. MySQL分页插件\n对应表Example类增加了Mysql分页方法，limit(Integer rows)、limit(Integer offset, Integer rows)和page(Integer page, Integer pageSize)  \n\u003ewarning: 分页默认从0开始，目前网上流行的大多数前端框架分页都是从0开始，插件保持这种方式（可通过配置startPage参数修改）； \n\n插件：\n```xml\n\u003c!-- MySQL分页插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.LimitPlugin\"\u003e\n    \u003c!-- 通过配置startPage影响Example中的page方法开始分页的页码，默认分页从0开始 --\u003e\n    \u003cproperty name=\"startPage\" value=\"0\"/\u003e\n\u003c/plugin\u003e\n```\n使用：  \n```java\npublic class TbExample {\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    protected Integer offset;\n\n    /**\n     * This field was generated by MyBatis Generator.\n     * This field corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    protected Integer rows;\n    \n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    public TbExample limit(Integer rows) {\n        this.rows = rows;\n        return this;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    public TbExample limit(Integer offset, Integer rows) {\n        this.offset = offset;\n        this.rows = rows;\n        return this;\n    }\n\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table tb\n     *\n     * @mbg.generated\n     * @project https://github.com/itfsw/mybatis-generator-plugin\n     */\n    public TbExample page(Integer page, Integer pageSize) {\n        this.offset = page * pageSize;\n        // !!! 如果配置了startPage且不为0\n        // this.offset = (page - startPage) * pageSize;\n        this.rows = pageSize;\n        return this;\n    }\n    \n    // offset 和 rows 的getter\u0026setter\n    \n    // 修正了clear方法\n    /**\n     * This method was generated by MyBatis Generator.\n     * This method corresponds to the database table tb\n     *\n     * @mbg.generated\n     */\n    public void clear() {\n        oredCriteria.clear();\n        orderByClause = null;\n        distinct = false;\n        rows = null;\n        offset = null;\n    }\n}\npublic class Test {\n    public static void main(String[] args) {\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1GreaterThan(1)\n                .example()\n                .limit(10)  // 查询前10条\n                .limit(10, 10)  // 查询10~20条\n                .page(1, 10)    // 查询第2页数据（每页10条）\n        );\n    }\n}\n```\n### 3. 数据Model链式构建插件\n这个是仿jquery的链式调用强化了表的Model的赋值操作  \n插件：\n```xml\n\u003c!-- 数据Model链式构建插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.ModelBuilderPlugin\"/\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 直接new表Model的内部Builder类，赋值后调用build()方法返回对象\n        Tb table = new Tb.Builder()\n               .field1(\"xx\")\n               .field2(\"xx\")\n               .field3(\"xx\")\n               .field4(\"xx\")\n               .build();\n        // 或者使用builder静态方法创建Builder\n        Tb table = Tb.builder()\n               .field1(\"xx\")\n               .field2(\"xx\")\n               .field3(\"xx\")\n               .field4(\"xx\")\n               .build();\n    }\n}\n```\n### 4. Example 增强插件(example,andIf,orderBy)\n* Criteria的快速返回example()方法。  \n* ~~Criteria链式调用增强，以前如果有按条件增加的查询语句会打乱链式查询构建，现在有了andIf(boolean ifAdd, CriteriaAdd add)方法可一直使用链式调用下去。~~\n* Example增强了setOrderByClause方法，新增orderBy(String orderByClause)、orderBy(String ... orderByClauses)方法直接返回example，增强链式调用，配合数据Model属性对应Column获取插件（ModelColumnPlugin）使用效果更佳。 \n* 增加基于column的操作，当配置了[数据Model属性对应Column获取插件（ModelColumnPlugin）](#8-数据model属性对应column获取插件)插件时，提供column之间的比对操作。  \n* 增加createCriteria静态方法newAndCreateCriteria简写example的创建。\n* 增加when方法（Example和Criteria都有），方便根据不同条件附加对应操作。\n\n插件：\n```xml\n\u003c!-- Example Criteria 增强插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin\"\u003e\n    \u003c!-- 是否支持已经过时的andIf方法（推荐使用when代替），默认支持 --\u003e\n    \u003cproperty name=\"enableAndIf\" value=\"true\"/\u003e\n\u003c/plugin\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // -----------------------------------example-----------------------------------\n        // 表Example.Criteria增加了工厂方法example()支持，使用后可链式构建查询条件使用example()返回Example对象\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1EqualTo(1)\n                .andField2EqualTo(\"xxx\")\n                .example()\n        );\n        \n        // ----------------- andIf （@Deprecated 尽量使用when代替）  ---------------------\n        // Criteria增强了链式调用，现在一些按条件增加的查询条件不会打乱链式调用了\n        // old\n        TbExample oldEx = new TbExample();\n        TbExample.Criteria criteria = oldEx\n                .createCriteria()\n                .andField1EqualTo(1)\n                .andField2EqualTo(\"xxx\");\n        // 如果随机数大于0.5，附加Field3查询条件\n        if (Math.random() \u003e 0.5){\n            criteria.andField3EqualTo(2)\n                    .andField4EqualTo(new Date());\n        }\n        this.tbMapper.selectByExample(oldEx);\n\n        // new\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1EqualTo(1)\n                .andField2EqualTo(\"xxx\")\n                // 如果随机数大于0.5，附加Field3查询条件\n                .andIf(Math.random() \u003e 0.5, new TbExample.Criteria.ICriteriaAdd() {\n                    @Override\n                    public TbExample.Criteria add(TbExample.Criteria add) {\n                        return add.andField3EqualTo(2)\n                                .andField4EqualTo(new Date());\n                    }\n                })\n                // 当然最简洁的写法是采用java8的Lambda表达式，当然你的项目是Java8+\n                .andIf(Math.random() \u003e 0.5, add -\u003e add\n                        .andField3EqualTo(2)\n                        .andField4EqualTo(new Date())\n                )\n                .example()\n        );\n        \n        // -----------------------------------when-----------------------------------\n        this.tbMapper.selectByExample(\n                TbExample.newAndCreateCriteria()\n                // 如果随机数大于1，附加Field3查询条件\n                .when(Math.random() \u003e 1, new TbExample.ICriteriaWhen() {\n                    @Override\n                    public void criteria(TbExample.Criteria criteria) {\n                        criteria.andField3EqualTo(2);\n                    }\n                })\n                // 当然最简洁的写法是采用java8的Lambda表达式，当然你的项目是Java8+\n                .when(Math.random() \u003e 1, criteria -\u003e criteria.andField3EqualTo(2))\n                // 也支持 if else 这种写法\n                .when(Math.random() \u003e 1, criteria -\u003e criteria.andField3EqualTo(2), criteria -\u003e criteria.andField3EqualTo(3))\n                .example()\n                // example上也支持 when 方法\n                .when(true, example -\u003e example.orderBy(\"field1 DESC\"))\n        );\n        \n        // -----------------------------------orderBy-----------------------------------\n        // old\n        TbExample ex = new TbExample();\n        ex.createCriteria().andField1GreaterThan(1);\n        ex.setOrderByClause(\"field1 DESC\");\n        this.tbMapper.selectByExample(ex);\n\n        // new\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1GreaterThan(1)\n                .example()\n                .orderBy(\"field1 DESC\")\n                // 这个配合数据Model属性对应Column获取插件（ModelColumnPlugin）使用\n                .orderBy(Tb.Column.field1.asc(), Tb.Column.field3.desc())\n        );\n        \n        // -----------------------------------column-----------------------------------\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1EqualToColumn(Tb.Column.field2)   // where field1 = field2\n                .andField1NotEqualToColumn(Tb.Column.field2)    // where field1 \u003c\u003e field2\n                .andField1GreaterThanColumn(Tb.Column.field2)   // where field1 \u003e field2\n                .andField1GreaterThanOrEqualToColumn(Tb.Column.field2)  // where field1 \u003e= field2\n                .andField1LessThanColumn(Tb.Column.field2)  // where field1 \u003c field2\n                .andField1LessThanOrEqualToColumn(Tb.Column.field2) // where field1 \u003c= field2\n                .example()\n        );\n        \n        // ---------------------------- static createCriteria  -----------------------\n        // simple\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .example()\n        );\n        // new\n        this.tbMapper.selectByExample(\n                TbExample.newAndCreateCriteria()\n                .example()\n        );\n    }\n}\n```\n### 5. Example 目标包修改插件\nMybatis Generator 插件默认把Model类和Example类都生成到一个包下，这样该包下类就会很多不方便区分，该插件目的就是把Example类独立到一个新包下，方便查看。  \n插件：\n```xml\n\u003c!-- Example 目标包修改插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.ExampleTargetPlugin\"\u003e\n    \u003c!-- 修改Example类生成到目标包下 --\u003e\n    \u003cproperty name=\"targetPackage\" value=\"com.itfsw.mybatis.generator.dao.example\"/\u003e\n\u003c/plugin\u003e\n```\n### 6. 批量插入插件\n提供了批量插入batchInsert和batchInsertSelective方法，需配合数据Model属性对应Column获取插件（ModelColumnPlugin）插件使用，实现类似于insertSelective插入列！    \n\u003ewarning: 插件生成的batchInsertSelective方法在使用时必须指定selective列，因为插件本身是预编译生成sql,对于批量数据是无法提供类似insertSelective非空插入的方式的;    \n\n插件：\n```xml\n\u003c!-- 批量插入插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.BatchInsertPlugin\"\u003e\n    \u003c!-- \n    开启后可以实现官方插件根据属性是否为空决定是否插入该字段功能\n    ！需开启allowMultiQueries=true多条sql提交操作，所以不建议使用！插件默认不开启\n    --\u003e\n    \u003cproperty name=\"allowMultiQueries\" value=\"false\"/\u003e\n\u003c/plugin\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 构建插入数据\n        List\u003cTb\u003e list = new ArrayList\u003c\u003e();\n        list.add(\n                Tb.builder()\n                .field1(0)\n                .field2(\"xx0\")\n                .field3(0)\n                .createTime(new Date())\n                .build()\n        );\n        list.add(\n                Tb.builder()\n                .field1(1)\n                .field2(\"xx1\")\n                .field3(1)\n                .createTime(new Date())\n                .build()\n        );\n        // 普通插入，插入所有列\n        this.tbMapper.batchInsert(list);\n        // !!!下面按需插入指定列（类似于insertSelective），需要数据Model属性对应Column获取插件（ModelColumnPlugin）插件\n        this.tbMapper.batchInsertSelective(list, Tb.Column.field1, Tb.Column.field2, Tb.Column.field3, Tb.Column.createTime);\n        // 或者排除某些列\n        this.tbMapper.batchInsertSelective(list, Tb.Column.excludes(Tb.Column.id, Tb.Column.delFlag));\n    }\n}\n```\n### 7. 逻辑删除插件\n因为很多实际项目数据都不允许物理删除，多采用逻辑删除，所以单独为逻辑删除做了一个插件，方便使用。  \n- 增加logicalDeleteByExample和logicalDeleteByPrimaryKey方法；\n- 增加selectByPrimaryKeyWithLogicalDelete方法（[[pull#12]](https://github.com/itfsw/mybatis-generator-plugin/pull/12)）；\n- 查询构造工具中增加逻辑删除条件andLogicalDeleted(boolean)；\n- 数据Model增加逻辑删除条件andLogicalDeleted(boolean)；\n- 增加逻辑删除常量IS_DELETED（已删除 默认值）、NOT_DELETED（未删除 默认值）（[[issues#11]](https://github.com/itfsw/mybatis-generator-plugin/issues/11)）；\n- 增加逻辑删除枚举；\n\n\u003ewarning: 注意在配合[状态枚举生成插件（EnumTypeStatusPlugin）](#21-状态枚举生成插件)使用时的注释格式，枚举数量必须大于等于2，且逻辑删除和未删除的值能在枚举中找到。\n \n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 逻辑删除插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.LogicalDeletePlugin\"\u003e\n        \u003c!-- 这里配置的是全局逻辑删除列和逻辑删除值，当然在table中配置的值会覆盖该全局配置 --\u003e\n        \u003c!-- 逻辑删除列类型只能为数字、字符串或者布尔类型 --\u003e\n        \u003cproperty name=\"logicalDeleteColumn\" value=\"del_flag\"/\u003e\n        \u003c!-- 逻辑删除-已删除值 --\u003e\n        \u003cproperty name=\"logicalDeleteValue\" value=\"9\"/\u003e\n        \u003c!-- 逻辑删除-未删除值 --\u003e\n        \u003cproperty name=\"logicalUnDeleteValue\" value=\"0\"/\u003e\n        \n        \u003c!-- 是否生成逻辑删除常量(只有开启时 logicalDeleteConstName、logicalUnDeleteConstName 才生效) --\u003e\n        \u003cproperty name=\"enableLogicalDeleteConst\" value=\"true\"/\u003e\n        \u003c!-- 逻辑删除常量名称，不配置默认为 IS_DELETED --\u003e\n        \u003cproperty name=\"logicalDeleteConstName\" value=\"IS_DELETED\"/\u003e\n        \u003c!-- 逻辑删除常量（未删除）名称，不配置默认为 NOT_DELETED --\u003e\n        \u003cproperty name=\"logicalUnDeleteConstName\" value=\"NOT_DELETED\"/\u003e\n    \u003c/plugin\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 这里可以单独表配置逻辑删除列和删除值，覆盖全局配置 --\u003e\n        \u003cproperty name=\"logicalDeleteColumn\" value=\"del_flag\"/\u003e\n        \u003cproperty name=\"logicalDeleteValue\" value=\"1\"/\u003e\n        \u003cproperty name=\"logicalUnDeleteValue\" value=\"-1\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 1. 逻辑删除ByExample\n        this.tbMapper.logicalDeleteByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1EqualTo(1)\n                .example()\n        );\n\n        // 2. 逻辑删除ByPrimaryKey\n        this.tbMapper.logicalDeleteByPrimaryKey(1L);\n\n        // 3. 同时Example中提供了一个快捷方法来过滤逻辑删除数据\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1EqualTo(1)\n                // 新增了一个andDeleted方法过滤逻辑删除数据\n                .andLogicalDeleted(true)\n                // 当然也可直接使用逻辑删除列的查询方法，我们数据Model中定义了一个逻辑删除常量DEL_FLAG\n                .andDelFlagEqualTo(Tb.IS_DELETED)\n                .example()\n        );\n        \n        // 4. 逻辑删除和未删除常量\n        Tb tb = Tb.builder()\n                .delFlag(Tb.IS_DELETED)   // 删除\n                .delFlag(Tb.NOT_DELETED)    // 未删除\n                .build()\n                .andLogicalDeleted(true);   // 也可以在这里使用true|false设置逻辑删除\n\n        // 5. selectByPrimaryKeyWithLogicalDelete V1.0.18 版本增加\n        // 因为之前觉得既然拿到了主键这种查询没有必要，但是实际使用中可能存在根据主键判断是否逻辑删除的情况，这种场景还是有用的\n        this.tbMapper.selectByPrimaryKeyWithLogicalDelete(1, true);\n        \n        // 6. 使用逻辑删除枚举\n        Tb tb = Tb.builder()\n                .delFlag(Tb.DelFlag.IS_DELETED)   // 删除\n                .delFlag(Tb.DelFlag.NOT_DELETED)    // 未删除\n                .build()\n                .andLogicalDeleted(true);   // 也可以在这里使用true|false设置逻辑删除\n    }\n}\n```\n通过注解覆盖逻辑删除配置\n```sql\nCREATE TABLE `tb` (\n  `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '注释1',\n  `del_flag` smallint(3) COMMENT '注释[enable(1):第一项必须是代表未删除, disable(0):第二项必须是代表已删除, other(2):当然还可以附加其他状态]',\n  PRIMARY KEY (`id`)\n);\n```\n```java\n/**\n * 生成的Tb会根据注释覆盖逻辑删除配置\n */\npublic class Tb {\n    public static final Short ENABLE = DelFlag.ENABLE.value();\n    public static final Short DISABLE = DelFlag.DISABLE.value();\n    \n    public enum DelFlag {\n        ENABLE(new Short(\"1\"), \"第一项必须是代表未删除\"),\n        DISABLE(new Short(\"0\"), \"第二项必须是代表已删除\"),\n        OTHER(new Short(\"2\"), \"当然还可以附加其他状态\");\n        \n        private final Short value;\n        private final String name;\n        \n        DelFlag(Short value, String name) {\n            this.value = value;\n            this.name = name;\n        }\n        \n        public Short getValue() {\n            return this.value;\n        }\n        public Short value() {\n            return this.value;\n        }\n        public String getName() {\n            return this.name;\n        }\n    }\n}\n```\n\n### 8. 数据Model属性对应Column获取插件\n项目中我们有时需要获取数据Model对应数据库字段的名称，一般直接根据数据Model的属性就可以猜出数据库对应column的名字，可是有的时候当column使用了columnOverride或者columnRenamingRule时就需要去看数据库设计了，所以提供了这个插件获取model对应的数据库Column。  \n* 配合Example Criteria 增强插件（ExampleEnhancedPlugin）使用，这个插件还提供了asc()和desc()方法配合Example的orderBy方法效果更佳。\n* 配合批量插入插件（BatchInsertPlugin）使用，batchInsertSelective(@Param(\"list\") List\u003cXXX\u003e list, @Param(\"selective\") XXX.Column ... insertColumns)。  \n* 提供静态excludes方法来进行快速反选。  \n\n插件：\n```xml\n\u003c!-- 数据Model属性对应Column获取插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.ModelColumnPlugin\"/\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 1. 获取Model对应column\n        String column = Tb.Column.createTime.value();\n\n        // 2. 配合Example Criteria 增强插件（ExampleEnhancedPlugin）使用orderBy方法\n        // old\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1GreaterThan(1)\n                .example()\n                .orderBy(\"field1 DESC, field3 ASC\")\n        );\n\n        // better\n        this.tbMapper.selectByExample(\n                new TbExample()\n                .createCriteria()\n                .andField1GreaterThan(1)\n                .example()\n                .orderBy(Tb.Column.field1.desc(), Tb.Column.field3.asc())\n        );\n        \n        // 3. 配合批量插入插件（BatchInsertPlugin）使用实现按需插入指定列\n        List\u003cTb\u003e list = new ArrayList\u003c\u003e();\n        list.add(\n                Tb.builder()\n                .field1(0)\n                .field2(\"xx0\")\n                .field3(0)\n                .field4(new Date())\n                .build()\n        );\n        list.add(\n                Tb.builder()\n                .field1(1)\n                .field2(\"xx1\")\n                .field3(1)\n                .field4(new Date())\n                .build()\n        );\n        // 这个会插入表所有列\n        this.tbMapper.batchInsert(list);\n        // 下面按需插入指定列（类似于insertSelective）\n        this.tbMapper.batchInsertSelective(list, Tb.Column.field1, Tb.Column.field2, Tb.Column.field3, Tb.Column.createTime);\n        \n        // 4. excludes 方法\n        this.tbMapper.batchInsertSelective(list, Tb.Column.excludes(Tb.Column.id, Tb.Column.delFlag));\n        \n        // 5. all 方法\n        this.tbMapper.batchInsertSelective(list, Tb.Column.all());\n    }\n}\n```\n### 9. 存在即更新插件\n1. 使用MySQL的[“insert ... on duplicate key update”](https://dev.mysql.com/doc/refman/5.7/en/insert-on-duplicate.html)实现存在即更新操作，简化数据入库操作（[[issues#2]](https://github.com/itfsw/mybatis-generator-plugin/issues/2)）。  \n2. 在开启allowMultiQueries=true（默认不会开启）情况下支持upsertByExample，upsertByExampleSelective操作，但强力建议不要使用（需保证团队没有使用statement提交sql,否则会存在sql注入风险）（[[issues#2]](https://github.com/itfsw/mybatis-generator-plugin/issues/2)）。\n\n插件：\n```xml\n\u003c!-- 存在即更新插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.UpsertPlugin\"\u003e\n    \u003c!-- \n    支持upsertByExample，upsertByExampleSelective操作\n    ！需开启allowMultiQueries=true多条sql提交操作，所以不建议使用！插件默认不开启\n    --\u003e\n    \u003cproperty name=\"allowMultiQueries\" value=\"false\"/\u003e\n    \u003c!-- \n    开启批量功能，支持batchUpsert,batchUpsertWithBLOBs,batchUpserSelective \n    ！这几个方法中无法支持IncrementsPlugin的方法！插件默认不开启\n    --\u003e\n    \u003cproperty name=\"allowBatchUpsert\" value=\"fasle\"/\u003e\n\u003c/plugin\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 1. 未入库数据入库，执行insert\n        Tb tb = Tb.builder()\n                .field1(1)\n                .field2(\"xx0\")\n                .delFlag(Tb.DEL_FLAG_ON)\n                .build();\n        int k0 = this.tbMapper.upsert(tb);\n        // 2. 已入库数据再次入库,执行update（！！需要注意如触发update其返回的受影响行数为2）\n        tb.setField2(\"xx1\");\n        int k1 = this.tbMapper.upsert(tb);\n\n        // 3. 类似insertSelective实现选择入库\n        Tb tb1 = Tb.builder()\n                .field1(1)\n                .field2(\"xx0\")\n                .build();\n        int k2 = this.tbMapper.upsertSelective(tb1);\n        tb1.setField2(\"xx1\");\n        int k3 = this.tbMapper.upsertSelective(tb1);\n\n        // --------------------------------- allowMultiQueries=true ------------------------------\n        // 4. 开启allowMultiQueries后增加upsertByExample，upsertByExampleSelective但强力建议不要使用（需保证团队没有使用statement提交sql,否则会存在sql注入风险）\n        Tb tb2 = Tb.builder()\n                .field1(1)\n                .field2(\"xx0\")\n                .field3(1003)\n                .delFlag(Tb.DEL_FLAG_ON)\n                .build();\n        int k4 = this.tbMapper.upsertByExample(tb2,\n                new TbExample()\n                        .createCriteria()\n                        .andField3EqualTo(1003)\n                        .example()\n        );\n        tb2.setField2(\"xx1\");\n        // !!! upsertByExample,upsertByExampleSelective触发更新时，更新条数返回是有问题的，这里只会返回0\n        // 这是mybatis自身问题，也是不怎么建议开启allowMultiQueries功能原因之一\n        int k5 = this.tbMapper.upsertByExample(tb2,\n                new TbExample()\n                        .createCriteria()\n                        .andField3EqualTo(1003)\n                        .example()\n        );\n        // upsertByExampleSelective 用法类似\n        \n        // 当Model WithBLOBs 存在时上述方法增加对应的 WithBLOBs 方法，举例如下：\n        TbWithBLOBs tb3 = Tb.builder()\n                            .field1(1)\n                            .field2(\"xx0\")\n                            .delFlag(Tb.DEL_FLAG_ON)\n                            .build();\n        int k6 = this.tbMapper.upsertWithBLOBs(tb);\n        \n        // --------------------------------- allowBatchUpsert=true ------------------------------\n        List\u003cTb\u003e list = new ArrayList\u003c\u003e();\n        list.add(\n                Tb.builder()\n                .field1(0)\n                .field2(\"xx0\")\n                .field3(0)\n                .field4(new Date())\n                .build()\n        );\n        list.add(\n                Tb.builder()\n                .field1(1)\n                .field2(\"xx1\")\n                .field3(1)\n                .field4(new Date())\n                .build()\n        );\n        this.tbMapper.batchUpsert(list);    // 对于BLOBs 有batchUpsertWithBLOBs方法\n        this.tbMapper.batchUpsertSelective(list, Tb.Column.field1, Tb.Column.field2, Tb.Column.field3, Tb.Column.createTime);\n        this.tbMapper.batchUpsertSelective(list, Tb.Column.excludes(Tb.Column.id, Tb.Column.delFlag)); // 排除某些列\n    }\n}\n```\n### 10. Selective选择插入更新增强插件\n项目中往往需要指定某些字段进行插入或者更新，或者把某些字段进行设置null处理，这种情况下原生xxxSelective方法往往不能达到需求，因为它的判断条件是对象字段是否为null，这种情况下可使用该插件对xxxSelective方法进行增强。  \n\u003ewarning: 以前老版本（1.1.x）插件处理需要指定的列时是放入Model中指定的，但在实际使用过程中有同事反馈这个处理有点反直觉，导致某些新同事不能及时找到对应方法，而且和增强的SelectSelectivePlugin以及UpsertSelective使用方式都不一致，所以统一修改之。  \n\n插件：\n```xml\n\u003c!-- Selective选择插入更新增强插件 --\u003e\n\u003cplugin type=\"com.itfsw.mybatis.generator.plugins.SelectiveEnhancedPlugin\"/\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // ------------------------------ 新版本（SelectiveEnhancedPlugin）--------------------------------\n        // 1. 指定插入或更新字段\n        Tb tb = Tb.builder()\n                .field1(1)\n                .field2(\"xx2\")\n                .field3(1)\n                .createTime(new Date())\n                .build();\n        // 只插入或者更新field1,field2字段\n        this.tbMapper.insertSelective(tb, Tb.Column.field1, Tb.Column.field2);\n        this.tbMapper.updateByExampleSelective(\n                tb,\n                new TbExample()\n                        .createCriteria()\n                        .andIdEqualTo(1l)\n                        .example(),\n                Tb.Column.field1, Tb.Column.field2\n        );\n        this.tbMapper.updateByPrimaryKeySelective(tb, Tb.Column.field1, Tb.Column.field2);\n        this.tbMapper.upsertSelective(tb, Tb.Column.field1, Tb.Column.field2);\n        this.tbMapper.upsertByExampleSelective(\n                tb,\n                new TbExample()\n                        .createCriteria()\n                        .andField3EqualTo(1)\n                        .example(),\n                Tb.Column.field1, Tb.Column.field2\n        );\n\n        // 2. 更新某些字段为null\n        this.tbMapper.updateByPrimaryKeySelective(\n                Tb.builder()\n                .id(1l)\n                .field1(null)   // 方便展示，不用设也可以\n                .build(),\n                Tb.Column.field1\n        );\n        \n        // 3. 排除某些列\n        this.tbMapper.insertSelective(tb, Tb.Column.excludes(Tb.Column.id, Tb.Column.delFlag));\n    }\n}\n```\n### 11. Table增加前缀插件\n项目中有时会遇到配置多数据源对应多业务的情况，这种情况下可能会出现不同数据源出现重复表名，造成异常冲突。\n该插件允许为表增加前缀，改变最终生成的Model、Mapper、Example类名以及xml名。  \n\u003ewarning: 使用[Table重命名插件](12-table重命名插件)可以实现相同功能！  \n\u003ewarning: 官方最新版本中已提供domainObjectRenamingRule支持(可以配合[表重命名配置插件](#18-表重命名配置插件)进行全局配置)！  \n```xml\n\u003ctable tableName=\"tb\"\u003e\n    \u003cdomainObjectRenamingRule searchString=\"^\" replaceString=\"DB1\" /\u003e\n\u003c/table\u003e\n```\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- Table增加前缀插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.TablePrefixPlugin\"\u003e\n        \u003c!-- 这里配置的是全局表前缀，当然在table中配置的值会覆盖该全局配置 --\u003e\n        \u003cproperty name=\"prefix\" value=\"Cm\"/\u003e\n    \u003c/plugin\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 这里可以单独表配置前缀，覆盖全局配置 --\u003e\n        \u003cproperty name=\"suffix\" value=\"Db1\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // Tb 表对应的Model、Mapper、Example类都增加了Db1的前缀\n        // Model类名: Tb -\u003e Db1Tb\n        // Mapper类名: TbMapper -\u003e Db1TbMapper\n        // Example类名: TbExample -\u003e Db1TbExample\n        // xml文件名: TbMapper.xml -\u003e Db1TbMapper.xml\n    }\n}\n```\n### 12. Table重命名插件\n插件由来：  \n记得才开始工作时某个隔壁项目组的坑爹项目，由于某些特定的原因数据库设计表名为t1~tn,字段名为f1~fn。\n这种情况下如何利用Mybatis Generator生成可读的代码呢，字段可以用columnOverride来替换，Model、Mapper等则需要使用domainObjectName+mapperName来实现方便辨识的代码。  \n\u003e该插件解决：domainObjectName+mapperName?好吧我想简化一下，所以直接使用tableOverride（仿照columnOverride）来实现便于配置的理解。 \n\n某些DBA喜欢在数据库设计时使用t_、f_这种类似的设计（[[issues#4]](https://github.com/itfsw/mybatis-generator-plugin/issues/4)），\n这种情况下我们就希望能有类似[columnRenamingRule](http://www.mybatis.org/generator/configreference/columnRenamingRule.html)这种重命名插件来修正最终生成的Model、Mapper等命名。\n\u003e该插件解决：使用正则替换table生成的Model、Example、Mapper等命名。\n \n项目中有时会遇到配置多数据源对应多业务的情况，这种情况下可能会出现不同数据源出现重复表名，造成异常冲突。\n该插件可以实现和[Table增加前缀插件](11-table增加前缀插件)相同的功能，仿照如下配置。  \n```xml\n\u003cproperty name=\"searchString\" value=\"^\"/\u003e\n\u003cproperty name=\"replaceString\" value=\"DB1\"/\u003e\n```\n\u003ewarning: 官方最新版本中已提供domainObjectRenamingRule支持(可以配合[表重命名配置插件](#18-表重命名配置插件)进行全局配置)！  \n```xml\n\u003ctable tableName=\"tb\"\u003e\n    \u003cdomainObjectRenamingRule searchString=\"^T\" replaceString=\"\" /\u003e\n\u003c/table\u003e\n``` \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- Table重命名插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.TableRenamePlugin\"\u003e\n        \u003c!-- 可根据具体需求确定是否配置 --\u003e\n        \u003cproperty name=\"searchString\" value=\"^T\"/\u003e\n        \u003cproperty name=\"replaceString\" value=\"\"/\u003e\n    \u003c/plugin\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 这个优先级最高，会忽略searchString、replaceString的配置 --\u003e\n        \u003cproperty name=\"tableOverride\" value=\"TestDb\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 1. 使用searchString和replaceString时，和Mybatis Generator一样使用的是java.util.regex.Matcher.replaceAll去进行正则替换\n        // 表： T_USER\n        // Model类名: TUser -\u003e User\n        // Mapper类名: TUserMapper -\u003e UserMapper\n        // Example类名: TUserExample -\u003e UserExample\n        // xml文件名: TUserMapper.xml -\u003e UserMapper.xml\n        \n        // 2. 使用表tableOverride时，该配置优先级最高\n        // 表： T_BOOK\n        // Model类名: TBook -\u003e TestDb\n        // Mapper类名: TBookMapper -\u003e TestDbMapper\n        // Example类名: TBookExample -\u003e TestDbExample\n        // xml文件名: TBookMapper.xml -\u003e TestDbMapper.xml\n    }\n}\n```\n### 13. 自定义注释插件\nMybatis Generator是原生支持自定义注释的（commentGenerator配置type属性），但使用比较麻烦需要自己实现CommentGenerator接口并打包配置赖等等。  \n该插件借助freemarker极佳的灵活性实现了自定义注释的快速配置。  \n\u003ewarning: 下方提供了一个参考模板，需要注意${mgb}的输出，因为Mybatis Generator就是通过该字符串判断是否为自身生成代码进行覆盖重写。  \n\n\u003ewarning: 请注意拷贝参考模板注释前方空格，idea等工具拷贝进去后自动格式化会造成格式错乱。 \n\n\u003ewarning: 模板引擎采用的是freemarker所以一些freemarker指令参数（如：\u003c#if xx\u003e\u003c/#if\u003e、${.now?string(\"yyyy-MM-dd HH:mm:ss\")}）都是可以使用的，请自己尝试。\n\n\u003ewarning: [默认模板](https://github.com/itfsw/mybatis-generator-plugin/blob/master/src/main/resources/default-comment.ftl)\n\n| 注释ID | 传入参数 | 备注 |\n| ----- | ----- | ---- |\n| addJavaFileComment | mgb\u003cbr\u003e[compilationUnit](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/CompilationUnit.java) | Java文件注释   |\n| addComment | mgb\u003cbr\u003e[xmlElement](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/XmlElement.java) | Xml节点注释  |\n| addRootComment | mgb\u003cbr\u003e[rootElement](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/xml/XmlElement.java) | Xml根节点注释  |\n| addFieldComment | mgb\u003cbr\u003e[field](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/Field.java)\u003cbr\u003e[introspectedTable](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/IntrospectedTable.java)\u003cbr\u003e[introspectedColumn](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/IntrospectedColumn.java) | Java 字段注释(非生成Model对应表字段时，introspectedColumn可能不存在)  |\n| addModelClassComment | mgb\u003cbr\u003e[topLevelClass](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/TopLevelClass.java)\u003cbr\u003eintrospectedTable | 表Model类注释  |\n| addClassComment | mgb\u003cbr\u003e[innerClass](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/InnerClass.java)\u003cbr\u003eintrospectedTable | 类注释  |\n| addEnumComment | mgb\u003cbr\u003e[innerEnum](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/InnerEnum.java)\u003cbr\u003eintrospectedTable | 枚举注释  |\n| addInterfaceComment | mgb\u003cbr\u003e[innerInterface](https://github.com/itfsw/mybatis-generator-plugin/blob/master/src/main/java/com/itfsw/mybatis/generator/plugins/utils/enhanced/InnerInterface.java)\u003cbr\u003eintrospectedTable | 接口注释(itfsw插件新增类型)  |\n| addGetterComment | mgb\u003cbr\u003e[method](https://github.com/mybatis/generator/blob/master/core/mybatis-generator-core/src/main/java/org/mybatis/generator/api/dom/java/Method.java)\u003cbr\u003eintrospectedTable\u003cbr\u003eintrospectedColumn | getter方法注释(introspectedColumn可能不存在)  |\n| addSetterComment | mgb\u003cbr\u003emethod\u003cbr\u003eintrospectedTable\u003cbr\u003eintrospectedColumn | setter方法注释(introspectedColumn可能不存在)  |\n| addGeneralMethodComment | mgb\u003cbr\u003emethod\u003cbr\u003eintrospectedTable | 方法注释  |\n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 自定义注释插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.CommentPlugin\"\u003e\n        \u003c!-- 自定义模板路径 --\u003e\n        \u003cproperty name=\"template\" value=\"src/main/resources/mybatis-generator-comment.ftl\" /\u003e\n    \u003c/plugin\u003e\n\u003c/xml\u003e\n```\n使用（[参考模板](https://github.com/itfsw/mybatis-generator-plugin/blob/master/src/main/resources/default-comment.ftl)）：  \n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003ctemplate\u003e\n    \u003c!-- #############################################################################################################\n    /**\n     * This method is called to add a file level comment to a generated java file. This method could be used to add a\n     * general file comment (such as a copyright notice). However, note that the Java file merge function in Eclipse\n     * does not deal with this comment. If you run the generator repeatedly, you will only retain the comment from the\n     * initial run.\n     * \u003cp\u003e\n     *\n     * The default implementation does nothing.\n     *\n     * @param compilationUnit\n     *            the compilation unit\n     */\n    --\u003e\n    \u003ccomment ID=\"addJavaFileComment\"\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * This method should add a suitable comment as a child element of the specified xmlElement to warn users that the\n     * element was generated and is subject to regeneration.\n     *\n     * @param xmlElement\n     *            the xml element\n     */\n    --\u003e\n    \u003ccomment ID=\"addComment\"\u003e\u003c![CDATA[\n\u003c!--\n  WARNING - ${mgb}\n  This element is automatically generated by MyBatis Generator, do not modify.\n  @project https://github.com/itfsw/mybatis-generator-plugin\n--\u003e\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * This method is called to add a comment as the first child of the root element. This method could be used to add a\n     * general file comment (such as a copyright notice). However, note that the XML file merge function does not deal\n     * with this comment. If you run the generator repeatedly, you will only retain the comment from the initial run.\n     * \u003cp\u003e\n     *\n     * The default implementation does nothing.\n     *\n     * @param rootElement\n     *            the root element\n     */\n    --\u003e\n    \u003ccomment ID=\"addRootComment\"\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * This method should add a Javadoc comment to the specified field. The field is related to the specified table and\n     * is used to hold the value of the specified column.\n     * \u003cp\u003e\n     *\n     * \u003cb\u003eImportant:\u003c/b\u003e This method should add a the nonstandard JavaDoc tag \"@mbg.generated\" to the comment. Without\n     * this tag, the Eclipse based Java merge feature will fail.\n     *\n     * @param field\n     *            the field\n     * @param introspectedTable\n     *            the introspected table\n     * @param introspectedColumn\n     *            the introspected column\n     */\n    --\u003e\n    \u003ccomment ID=\"addFieldComment\"\u003e\u003c![CDATA[\n\u003c#if introspectedColumn??\u003e\n/**\n    \u003c#if introspectedColumn.remarks?? \u0026\u0026 introspectedColumn.remarks != ''\u003e\n * Database Column Remarks:\n        \u003c#list introspectedColumn.remarks?split(\"\\n\") as remark\u003e\n *   ${remark}\n        \u003c/#list\u003e\n    \u003c/#if\u003e\n *\n * This field was generated by MyBatis Generator.\n * This field corresponds to the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n\u003c#else\u003e\n/**\n * This field was generated by MyBatis Generator.\n * This field corresponds to the database table ${introspectedTable.fullyQualifiedTable}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n\u003c/#if\u003e\n    ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds a comment for a model class.  The Java code merger should\n     * be notified not to delete the entire class in case any manual\n     * changes have been made.  So this method will always use the\n     * \"do not delete\" annotation.\n     *\n     * Because of difficulties with the Java file merger, the default implementation\n     * of this method should NOT add comments.  Comments should only be added if\n     * specifically requested by the user (for example, by enabling table remark comments).\n     *\n     * @param topLevelClass\n     *            the top level class\n     * @param introspectedTable\n     *            the introspected table\n     */\n    --\u003e\n    \u003ccomment ID=\"addModelClassComment\"\u003e\u003c![CDATA[\n/**\n\u003c#if introspectedTable.remarks?? \u0026\u0026 introspectedTable.remarks != ''\u003e\n * Database Table Remarks:\n\u003c#list introspectedTable.remarks?split(\"\\n\") as remark\u003e\n *   ${remark}\n\u003c/#list\u003e\n\u003c/#if\u003e\n *\n * This class was generated by MyBatis Generator.\n * This class corresponds to the database table ${introspectedTable.fullyQualifiedTable}\n *\n * ${mgb} do_not_delete_during_merge\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds the inner class comment.\n     *\n     * @param innerClass\n     *            the inner class\n     * @param introspectedTable\n     *            the introspected table\n     * @param markAsDoNotDelete\n     *            the mark as do not delete\n     */\n    --\u003e\n    \u003ccomment ID=\"addClassComment\"\u003e\u003c![CDATA[\n/**\n * This class was generated by MyBatis Generator.\n * This class corresponds to the database table ${introspectedTable.fullyQualifiedTable}\n *\n * ${mgb}\u003c#if markAsDoNotDelete?? \u0026\u0026 markAsDoNotDelete\u003e do_not_delete_during_merge\u003c/#if\u003e\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds the enum comment.\n     *\n     * @param innerEnum\n     *            the inner enum\n     * @param introspectedTable\n     *            the introspected table\n     */\n    --\u003e\n    \u003ccomment ID=\"addEnumComment\"\u003e\u003c![CDATA[\n/**\n * This enum was generated by MyBatis Generator.\n * This enum corresponds to the database table ${introspectedTable.fullyQualifiedTable}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds the interface comment.\n     *\n     * @param innerInterface\n     *            the inner interface\n     * @param introspectedTable\n     *            the introspected table\n     */\n    --\u003e\n    \u003ccomment ID=\"addInterfaceComment\"\u003e\u003c![CDATA[\n/**\n * This interface was generated by MyBatis Generator.\n * This interface corresponds to the database table ${introspectedTable.fullyQualifiedTable}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds the getter comment.\n     *\n     * @param method\n     *            the method\n     * @param introspectedTable\n     *            the introspected table\n     * @param introspectedColumn\n     *            the introspected column\n     */\n    --\u003e\n    \u003ccomment ID=\"addGetterComment\"\u003e\u003c![CDATA[\n\u003c#if introspectedColumn??\u003e\n/**\n * This method was generated by MyBatis Generator.\n * This method returns the value of the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}\n *\n * @return the value of ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n\u003c#else\u003e\n/**\n * This method was generated by MyBatis Generator.\n * This method returns the value of the field ${method.name?replace(\"get\",\"\")?replace(\"is\", \"\")?uncap_first}\n *\n * @return the value of field ${method.name?replace(\"get\",\"\")?replace(\"is\", \"\")?uncap_first}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n\u003c/#if\u003e\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds the setter comment.\n     *\n     * @param method\n     *            the method\n     * @param introspectedTable\n     *            the introspected table\n     * @param introspectedColumn\n     *            the introspected column\n     */\n    --\u003e\n    \u003ccomment ID=\"addSetterComment\"\u003e\u003c![CDATA[\n\u003c#if introspectedColumn??\u003e\n/**\n * This method was generated by MyBatis Generator.\n * This method sets the value of the database column ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}\n *\n * @param ${method.parameters[0].name} the value for ${introspectedTable.fullyQualifiedTable}.${introspectedColumn.actualColumnName}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n\u003c#else\u003e\n/**\n * This method was generated by MyBatis Generator.\n * This method sets the value of the field ${method.name?replace(\"set\",\"\")?uncap_first}\n *\n * @param ${method.parameters[0].name} the value for field ${method.name?replace(\"set\",\"\")?uncap_first}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n\u003c/#if\u003e\n        ]]\u003e\u003c/comment\u003e\n\n    \u003c!-- #############################################################################################################\n    /**\n     * Adds the general method comment.\n     *\n     * @param method\n     *            the method\n     * @param introspectedTable\n     *            the introspected table\n     */\n    --\u003e\n    \u003ccomment ID=\"addGeneralMethodComment\"\u003e\u003c![CDATA[\n/**\n * This method was generated by MyBatis Generator.\n * This method corresponds to the database table ${introspectedTable.fullyQualifiedTable}\n *\n * ${mgb}\n * @project https://github.com/itfsw/mybatis-generator-plugin\n */\n        ]]\u003e\u003c/comment\u003e\n\u003c/template\u003e\n```\n### 14. 增量插件\n为更新操作生成set filedxxx = filedxxx +/- inc 操作，方便某些统计字段的更新操作，常用于某些需要计数的场景；  \n\n\u003ewarning：该插件在整合LombokPlugin使用时会生成大量附加代码影响代码美观，强力建议切换到新版插件[IncrementPlugin](#22-增量插件);    \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 增量插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.IncrementsPlugin\" /\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 配置需要进行增量操作的列名称（英文半角逗号分隔） --\u003e\n        \u003cproperty name=\"incrementsColumns\" value=\"field1,field2\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 在构建更新对象时，配置了增量支持的字段会增加传入增量枚举的方法\n        Tb tb = Tb.builder()\n                .id(102)\n                .field1(1, Tb.Builder.Inc.INC)  // 字段1 统计增加1\n                .field2(2, Tb.Builder.Inc.DEC)  // 字段2 统计减去2\n                .field4(new Date())\n                .build();\n        // 更新操作，可以是 updateByExample, updateByExampleSelective, updateByPrimaryKey\n        // , updateByPrimaryKeySelective, upsert, upsertSelective等所有涉及更新的操作\n        this.tbMapper.updateByPrimaryKey(tb);\n    }\n}\n```\n### 15. 查询结果选择性返回插件\n一般我们在做查询优化的时候会要求查询返回时不要返回自己不需要的字段数据，因为Sending data所花费的时间和加大内存的占用\n，所以我们看到官方对于大数据的字段会拆分成xxxWithBLOBs的操作，但是这种拆分还是不能精确到具体列返回。  \n所以该插件的作用就是精确指定查询操作所需要返回的字段信息，实现查询的精确返回。  \n\u003ewarning: 因为采用的是resultMap进行的属性绑定（即时设置了constructorBased=true也无效，因为参数个数不一致会导致异常，该插件也会另外生成一个基于属性绑定的resultMap），\n所以可能会出现list中存在null元素的问题，这个是mybatis自身机制造成的当查询出来的某行所有列都为null时不会生成对象（PS：其实这个不能算是错误，mybatis这样处理也说的通，但是在使用时还是要注意null的判断，当然如果有什么配置或者其他处理方式欢迎反馈哦）。  \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 查询结果选择性返回插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.SelectSelectivePlugin\" /\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 查询操作精确返回需要的列\n        this.tbMapper.selectByExampleSelective(\n            new TbExample()\n            .createCriteria()\n            .andField1GreaterThan(1)\n            .example(),\n            Tb.Column.field1,\n            Tb.Column.field2\n        );\n        // 同理还有 selectByPrimaryKeySelective，selectOneByExampleSelective（SelectOneByExamplePlugin插件配合使用）方法\n        \n        // 当然可以使用excludes\n        this.tbMapper.selectByExampleSelective(\n            new TbExample()\n            .createCriteria()\n            .andField1GreaterThan(1)\n            .example(),\n            Tb.Column.excludes(Tb.Column.id, Tb.Column.delFlag)\n        );\n    }\n}\n```\n### 16. 官方ConstructorBased配置BUG临时修正插件\n当javaModelGenerator配置constructorBased=true时，如果表中只有一个column类型为“blob”时java model没有生成BaseResultMap对应的构造函数，\n这个bug已经反馈给官方[issues#267](https://github.com/mybatis/generator/issues/267)。  \n\u003e 官方V1.3.6版本将解决这个bug,老版本的可以使用这个插件临时修正问题。  \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 官方ConstructorBased配置BUG临时修正插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.ConstructorBasedBugFixPlugin\" /\u003e\n\u003c/xml\u003e\n```\n### 17. 乐观锁插件\n为并发操作引入乐观锁，当发生删除或者更新操作时调用相应的WithVersion方法传入版本号，插件会在相应的查询条件上附加上版本号的检查，防止非法操作的发生。  \n同时在更新操作中支持自定义nextVersion或者利用sql 的“set column = column + 1”去维护版本号。   \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 乐观锁插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.OptimisticLockerPlugin\"\u003e\n        \u003c!-- 是否启用自定义nextVersion，默认不启用(插件会默认使用sql的 set column = column + 1) --\u003e\n        \u003cproperty name=\"customizedNextVersion\" value=\"false\"/\u003e\n    \u003c/plugin\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 这里可以单独表配置，覆盖全局配置 --\u003e\n        \u003cproperty name=\"customizedNextVersion\" value=\"true\"/\u003e\n        \u003c!-- 指定版本列 --\u003e\n        \u003cproperty name=\"versionColumn\" value=\"version\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // ============================ 带版本号的删除更新等操作 ===============================\n        int result = this.tbMapper.deleteWithVersionByExample(\n                        100, // 版本号\n                        new TbExample()\n                           .createCriteria()\n                           .andField1GreaterThan(1)\n                           .example()\n                     );\n        if (result == 0){\n            throw new Exception(\"没有找到数据或者数据版本号错误！\");\n        }\n        // 对应生成的Sql: delete from tb WHERE version = 100 and ( ( field1 \u003e 1 ) )\n        \n        // 带版本号的方法有：\n        // deleteWithVersionByExample、deleteWithVersionByPrimaryKey、\n        // updateWithVersionByExampleSelective、updateWithVersionByExampleWithBLOBs、updateWithVersionByExample\n        // updateWithVersionByPrimaryKeySelective、updateWithVersionByPrimaryKeyWithBLOBs、updateWithVersionByPrimaryKey\n        \n        // ============================= 使用默认版本号生成策略 ===========================\n        this.tbMapper.updateWithVersionByPrimaryKey(\n                100,    // 版本号\n                Tb.builder()\n                  .id(102)\n                  .field1(\"ts1\")\n                  .build()\n        );\n        // 对应生成的Sql: update tb set version = version + 1, field1 = 'ts1' where version = 100 and id = 102\n        \n        // ============================= 使用自定义版本号生成策略 ===========================\n        this.tbMapper.updateWithVersionByPrimaryKey(\n                100,    // 版本号\n                Tb.builder()\n                  .id(102)\n                  .field1(\"ts1\")\n                  .build()\n                  .nextVersion(System.currentTimeMillis())    // 传入nextVersion\n        );\n        // 对应生成的Sql: update tb set version = 1525773888559, field1 = 'ts1' where version = 100 and id = 102\n    }\n}\n```\n### 18. 表重命名配置插件\n官方提供了domainObjectRenamingRule(官方最新版本已提供)、columnRenamingRule分别进行生成的表名称和对应表字段的重命名支持，但是它需要每个表单独进行配置，对于常用的如表附带前缀“t_”、字段前缀“f_”这种全局性替换会比较麻烦。   \n该插件提供了一种全局替换机制，当表没有单独指定domainObjectRenamingRule、columnRenamingRule时采用全局性配置。   \n同时插件提供clientSuffix、exampleSuffix、modelSuffix来修改对应生成的类和文件的结尾（之前issue中有用户希望能把Mapper替换成Dao）。       \n- 全局domainObjectRenamingRule  \n```xml\n\u003cxml\u003e\n    \u003c!-- 表重命名配置插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin\"\u003e\n        \u003cproperty name=\"domainObjectRenamingRule.searchString\" value=\"^T\"/\u003e\n        \u003cproperty name=\"domainObjectRenamingRule.replaceString\" value=\"\"/\u003e\n    \u003c/plugin\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 这里可以禁用全局domainObjectRenamingRule配置 --\u003e\n        \u003cproperty name=\"domainObjectRenamingRule.disable\" value=\"true\"/\u003e\n    \u003c/table\u003e\n    \n    \u003ctable tableName=\"tb_ts1\"\u003e\n        \u003c!-- 当然你也可以使用官方domainObjectRenamingRule的配置来覆盖全局配置 --\u003e\n        \u003cdomainObjectRenamingRule searchString=\"^Tb\" replaceString=\"B\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n- 全局columnRenamingRule  \n```xml\n\u003cxml\u003e\n    \u003c!-- 表重命名配置插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin\"\u003e\n        \u003c!-- 需要注意，这里的正则和官方一样是比对替换都是原始表的column名称 --\u003e\n        \u003cproperty name=\"columnRenamingRule.searchString\" value=\"^f_\"/\u003e\n        \u003cproperty name=\"columnRenamingRule.replaceString\" value=\"_\"/\u003e\n    \u003c/plugin\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 这里可以禁用全局columnRenamingRule配置 --\u003e\n        \u003cproperty name=\"columnRenamingRule.disable\" value=\"true\"/\u003e\n    \u003c/table\u003e\n    \n    \u003ctable tableName=\"tb_ts1\"\u003e\n        \u003c!-- 当然你也可以使用官方domainObjectRenamingRule的配置来覆盖全局配置 --\u003e\n        \u003ccolumnRenamingRule searchString=\"^f_\" replaceString=\"_\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n- clientSuffix、exampleSuffix、modelSuffix  \n```xml\n\u003cxml\u003e\n    \u003c!-- 表重命名配置插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.TableRenameConfigurationPlugin\"\u003e\n        \u003c!-- TbMapper -\u003e TbDao, TbMapper.xml -\u003e TbDao.xml --\u003e\n        \u003cproperty name=\"clientSuffix\" value=\"Dao\"/\u003e\n        \u003c!-- TbExmaple -\u003e TbQuery --\u003e\n        \u003cproperty name=\"exampleSuffix\" value=\"Query\"/\u003e\n        \u003c!-- Tb -\u003e TbEntity --\u003e\n        \u003cproperty name=\"modelSuffix\" value=\"Entity\"/\u003e\n    \u003c/plugin\u003e\n\u003c/xml\u003e\n```\n### 19. Lombok插件\n使用Lombok的使用可以减少很多重复代码的书写，目前项目中已大量使用。\n但Lombok的@Builder对于类的继承支持很不好，最近发现新版(\u003e=1.18.2)已经提供了对@SuperBuilder的支持，所以新增该插件方便简写代码。\n\n\u003ewarning1: @Builder注解在Lombok 版本 \u003e= 1.18.2 的情况下才能开启，对于存在继承关系的model会自动替换成@SuperBuilder注解(目前IDEA的插件对于SuperBuilder的还不支持（作者已经安排上更新日程）, 可以开启配置supportSuperBuilderForIdea使插件在遇到@SuperBuilder注解时使用ModelBuilderPlugin替代该注解)。  \n\n\u003ewarning2: 配合插件IncrementsPlugin（已不推荐使用，请使用新版[IncrementPlugin](#22-增量插件)解决该问题） 并且 @Builder开启的情况下，因为@SuperBuilder的一些限制，\n插件模拟Lombok插件生成了一些附加代码可能在某些编译器上会提示错误，请忽略（Lombok = 1.18.2 已测试）。\n\n```xml\n\u003cxml\u003e\n    \u003c!-- Lombok插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.LombokPlugin\"\u003e\n        \u003c!-- @Data 默认开启,同时插件会对子类自动附加@EqualsAndHashCode(callSuper = true)，@ToString(callSuper = true) --\u003e\n        \u003cproperty name=\"@Data\" value=\"true\"/\u003e\n        \u003c!-- @Builder 必须在 Lombok 版本 \u003e= 1.18.2 的情况下开启，对存在继承关系的类自动替换成@SuperBuilder --\u003e\n        \u003cproperty name=\"@Builder\" value=\"false\"/\u003e\n        \u003c!-- @NoArgsConstructor 和 @AllArgsConstructor 使用规则和Lombok一致 --\u003e\n        \u003cproperty name=\"@AllArgsConstructor\" value=\"false\"/\u003e\n        \u003cproperty name=\"@NoArgsConstructor\" value=\"false\"/\u003e\n        \u003c!-- @Getter、@Setter、@Accessors 等使用规则参见官方文档 --\u003e\n        \u003cproperty name=\"@Accessors(chain = true)\" value=\"false\"/\u003e\n        \u003c!-- 临时解决IDEA工具对@SuperBuilder的不支持问题，开启后(默认未开启)插件在遇到@SuperBuilder注解时会调用ModelBuilderPlugin来生成相应的builder代码 --\u003e\n        \u003cproperty name=\"supportSuperBuilderForIdea\" value=\"false\"/\u003e\n    \u003c/plugin\u003e\n\u003c/xml\u003e\n```\n### 20. 数据ModelCloneable插件\n数据Model实现Cloneable接口。\n\n```xml\n\u003cxml\u003e\n    \u003c!-- 数据ModelCloneable插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.ModelCloneablePlugin\"/\u003e\n\u003c/xml\u003e\n```\n### 21. 状态枚举生成插件\n数据库中经常会定义一些状态字段，该工具可根据约定的注释格式生成对应的枚举类，方便使用。\n\u003ewarning：插件1.2.18版本以后默认开启自动扫描，根据约定注释格式自动生成对应枚举类\n```xml\n\u003cxml\u003e\n    \u003c!-- 状态枚举生成插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.EnumTypeStatusPlugin\"\u003e\n        \u003c!-- 是否开启自动扫描根据约定注释格式生成枚举，默认true --\u003e\n        \u003cproperty name=\"autoScan\" value=\"true\"/\u003e\n        \u003c!-- autoScan为false,这里可以定义全局需要检查生成枚举类的列名 --\u003e\n        \u003cproperty name=\"enumColumns\" value=\"type, status\"/\u003e\n    \u003c/plugin\u003e\n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- autoScan为false,也可以为单独某个table增加配置 --\u003e\n        \u003cproperty name=\"enumColumns\" value=\"user_type\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n\u003ewarning: 约定的注释检查规则的正则表达式如下\n```java\npublic class EnumTypeStatusPlugin {\n    public final static String REMARKS_PATTERN = \".*\\\\s*\\\\[\\\\s*(\\\\w+\\\\s*\\\\(\\\\s*[\\\\u4e00-\\\\u9fa5_\\\\-a-zA-Z0-9]+\\\\s*\\\\)\\\\s*:\\\\s*[\\\\u4e00-\\\\u9fa5_\\\\-a-zA-Z0-9]+\\\\s*\\\\,?\\\\s*)+\\\\s*\\\\]\\\\s*.*\";\n}\n\n```\n使用\n```sql\nCREATE TABLE `tb` (\n  `type` smallint(3) COMMENT '注释[success(0):成功, fail(1):失败]',\n  `status` bigint(3) COMMENT '换行的注释\n                                         [\n                                           login_success(0):登录成功,\n                                           login_fail(1):登录失败\n                                         ]',\n  `user_type` varchar(20) COMMENT '具体注释的写法是比较宽泛的，只要匹配上面正则就行\n   [    success (   我是具体值  )    : 我是值的描述_我可以是中英文数字和下划线_xxx_123, fail_xx_3\n    (1  ) :  失败] 后面也可以跟注释'                                       \n);\n```\n```java\npublic class Tb {\n    public enum Type {\n        SUCCESS((short)0, \"成功\"),\n        FAIL((short)1, \"失败\");\n        \n        private final Short value;\n        private final String name;\n        \n        Type(Short value, String name) {\n            this.value = value;\n            this.name = name;\n        }\n        public Short getValue() {\n            return this.value;\n        }\n        public Short value() {\n            return this.value;\n        }\n        public String getName() {\n            return this.name;\n        }\n        public Field2 parseValue(Short value) {\n            if (value != null) {\n                for (Field2 item : values()) {\n                    if (item.value.equals(value)) {\n                        return item;\n                    }\n                }\n            }\n            return null;\n        }\n        public Field2 parseName(String name) {\n            if (name != null) {\n                for (Field2 item : values()) {\n                    if (item.name.equals(name)) {\n                        return item;\n                    }\n                }\n            }\n            return null;\n        }\n    }\n\n    public enum Status {\n        LOGIN_SUCCESS(0L, \"登录成功\"),\n        LOGIN_FAIL(1L, \"登录失败\");\n\n        private final Long value;\n        private final String name;\n\n        Status(Long value, String name) {\n            this.value = value;\n            this.name = name;\n        }\n        public Long getValue() {\n            return this.value;\n        }\n        public Long value() {\n            return this.value;\n        }\n        public String getName() {\n            return this.name;\n        }\n        public Status parseValue(Short value) {\n            if (value != null) {\n                for (Status item : values()) {\n                    if (item.value.equals(value)) {\n                        return item;\n                    }\n                }\n            }\n            return null;\n        }\n        public Status parseName(String name) {\n            if (name != null) {\n                for (Status item : values()) {\n                    if (item.name.equals(name)) {\n                        return item;\n                    }\n                }\n            }\n            return null;\n        }\n    }\n\n    public enum UserType {\n        SUCCESS(\"我是具体值\", \"我是值的描述_我可以是中英文数字和下划线_xxx_123\"),\n        FAIL_XX_3(\"1\", \"失败\");\n\n        private final String value;\n        private final String name;\n\n        UserType(String value, String name) {\n            this.value = value;\n            this.name = name;\n        }\n        public String getValue() {\n            return this.value;\n        }\n        public String value() {\n            return this.value;\n        }\n        public String getName() {\n            return this.name;\n        }\n        public UserType parseValue(Short value) {\n            if (value != null) {\n                for (UserType item : values()) {\n                    if (item.value.equals(value)) {\n                        return item;\n                    }\n                }\n            }\n            return null;\n        }\n        public UserType parseName(String name) {\n            if (name != null) {\n                for (UserType item : values()) {\n                    if (item.name.equals(name)) {\n                        return item;\n                    }\n                }\n            }\n            return null;\n        }\n    }\n}\n```\n### 22. 增量插件\n为更新操作生成set filedxxx = filedxxx +/- inc 操作，方便某些统计字段的更新操作，常用于某些需要计数的场景,需配合（[ModelColumnPlugin](#8-数据model属性对应column获取插件)）插件使用；     \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- 增量插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.IncrementPlugin\" /\u003e\n    \n    \u003ctable tableName=\"tb\"\u003e\n        \u003c!-- 配置需要进行增量操作的列名称（英文半角逗号分隔） --\u003e\n        \u003cproperty name=\"incrementColumns\" value=\"field1,field2\"/\u003e\n    \u003c/table\u003e\n\u003c/xml\u003e\n```\n使用：  \n```java\npublic class Test {\n    public static void main(String[] args) {\n        // 在构建更新对象时，配置了增量支持的字段会增加传入增量枚举的方法\n        Tb tb = Tb.builder()\n                .id(102)\n                .field4(new Date())\n                .build()\n                .increment(Tb.Increment.field1.inc(1)) // 字段1 统计增加1\n                .increment(Tb.Increment.field2.dec(2)); // 字段2 统计减去2\n        // 更新操作，可以是 updateByExample, updateByExampleSelective, updateByPrimaryKey\n        // , updateByPrimaryKeySelective, upsert, upsertSelective等所有涉及更新的操作\n        this.tbMapper.updateByPrimaryKey(tb);\n    }\n}\n```\n### 23. Mapper注解插件\n对官方的（[MapperAnnotationPlugin](http://www.mybatis.org/generator/reference/plugins.html)）增强，可自定义附加@Repository注解（IDEA工具对@Mapper注解支持有问题，使用@Autowired会报无法找到对应bean，附加@Repository后解决）；     \n\n插件：\n```xml\n\u003cxml\u003e\n    \u003c!-- Mapper注解插件 --\u003e\n    \u003cplugin type=\"com.itfsw.mybatis.generator.plugins.MapperAnnotationPlugin\"\u003e\n        \u003c!-- @Mapper 默认开启 --\u003e\n        \u003cproperty name=\"@Mapper\" value=\"true\"/\u003e\n        \u003c!-- @Repository 开启后解决IDEA工具@Autowired报错 --\u003e\n        \u003cproperty name=\"@Repository\" value=\"org.springframework.stereotype.Repository\"/\u003e\n        \u003c!-- 其他自定义注解 --\u003e\n        \u003cproperty name=\"@DS(\u0026quot;master\u0026quot;)\" value=\"com.baomidou.dynamic.datasource.annotation.DS\"/\u003e\n    \u003c/plugin\u003e\n\u003c/xml\u003e\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitfsw%2Fmybatis-generator-plugin","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fitfsw%2Fmybatis-generator-plugin","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fitfsw%2Fmybatis-generator-plugin/lists"}