最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

MybatisPlus代碼生成器含XML文件詳解

 更新時(shí)間:2022年01月20日 15:09:52   作者:大佬喝可樂(lè)丶  
這篇文章主要介紹了MybatisPlus代碼生成器含XML文件詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

MybatisPlus代碼生成器含XML

所需依賴(lài)

? ? ? ? <!--Mybatis-Plus-->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.baomidou</groupId>
? ? ? ? ? ? <artifactId>mybatis-plus-boot-starter</artifactId>
? ? ? ? ? ? <version>3.4.0</version>
? ? ? ? </dependency>
? ? ? ? <!--Mybatis-Plus逆向工程-->
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>com.baomidou</groupId>
? ? ? ? ? ? <artifactId>mybatis-plus-generator</artifactId>
? ? ? ? ? ? <version>3.4.0</version>
? ? ? ? </dependency>
? ? ? ? <dependency>
? ? ? ? ? ? <groupId>org.freemarker</groupId>
? ? ? ? ? ? <artifactId>freemarker</artifactId>
? ? ? ? ? ? <version>2.3.30</version>
? ? ? ? </dependency>

代碼如下

需配置數(shù)據(jù)源包

目前僅支持Mysql,oracle測(cè)試未成功,若哪個(gè)大佬有oracle代碼生成器,謝謝分享:

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.core.exceptions.MybatisPlusException;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.InjectionConfig;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.po.TableInfo;
import com.baomidou.mybatisplus.generator.config.rules.DateType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
/**
 * Created with IntelliJ IDEA.
 *
 * @Auther: LYK
 * @Date: 2020/09/23/17:31
 * @Version: 1.0
 * @Description:代碼生成器
 */
public class CodeGenerator {
    /**
     * <p>
     * 讀取控制臺(tái)內(nèi)容
     * </p>
     */
    public static String scanner(String tip) {
        Scanner scanner = new Scanner(System.in);
        StringBuilder help = new StringBuilder();
        help.append("請(qǐng)輸入  " + tip + " :");
        System.out.println(help.toString());
        if (scanner.hasNext()) {
            String ipt = scanner.next();
            if (StringUtils.isNotBlank(ipt)) {
                return ipt;
            }
        }
        throw new MybatisPlusException("請(qǐng)輸入正確的" + tip + "!");
    }
    public static void main(String[] args) {
        // 代碼生成器
        AutoGenerator mpg = new AutoGenerator();
        // 全局配置
        GlobalConfig gc = new GlobalConfig();
        String projectPath = System.getProperty("user.dir");
        gc.setOutputDir(projectPath + "/src/main/java");
        gc.setOpen(false);
        gc.setAuthor("LYK"); //設(shè)置作者
        gc.setBaseResultMap(true) ;//XML中的ResultMap標(biāo)簽
        gc.setBaseColumnList(true); //XML標(biāo)簽
        gc.setFileOverride(true); //文件覆蓋設(shè)置
        gc.setIdType(IdType.AUTO); //主鍵策略
        gc.setMapperName("%sMapper");  //%s會(huì)自動(dòng)填充表實(shí)體屬性
        gc.setXmlName("%sMapper");
        gc.setServiceName("%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setControllerName("%sController");
        gc.setDateType(DateType.ONLY_DATE);
//         gc.setSwagger2(true); 實(shí)體屬性 Swagger2 注解
        mpg.setGlobalConfig(gc);
        // 數(shù)據(jù)源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setUrl("jdbc:mysql://localhost:3306/xxxx?serverTimezone=UTC&useUnicode=true&useSSL=false&characterEncoding=utf8");
        // dsc.setSchemaName("public");
        dsc.setDriverName("com.mysql.cj.jdbc.Driver");
        dsc.setUsername("xxxx");
        dsc.setPassword("xxxx");
        mpg.setDataSource(dsc);
        // 包配置
        PackageConfig pc = new PackageConfig();
//        pc.setModuleName(scanner("securityservice"));
        pc.setParent("com.xxx.xxx.xxx");
        mpg.setPackageInfo(pc);
        // 自定義配置
        InjectionConfig cfg = new InjectionConfig() {
            @Override
            public void initMap() {
                // to do nothing
            }
        };
        // 如果模板引擎是 freemarker
        String templatePath = "/templates/mapper.xml.ftl";
        // 如果模板引擎是 velocity
        // String templatePath = "/templates/mapper.xml.vm";
        // 自定義輸出配置
        List<FileOutConfig> focList = new ArrayList<>();
        // 自定義配置會(huì)被優(yōu)先輸出
        focList.add(new FileOutConfig(templatePath) {
            @Override
            public String outputFile(TableInfo tableInfo) {
                // 自定義輸出文件名 , 如果你 Entity 設(shè)置了前后綴、此處注意 xml 的名稱(chēng)會(huì)跟著發(fā)生變化?。?
                return projectPath + "/src/main/resources/mapper/" + pc.getModuleName()
                        + "/" + tableInfo.getEntityName() + "Mapper" + StringPool.DOT_XML;
            }
        });
        /*
        cfg.setFileCreate(new IFileCreate() {
            @Override
            public boolean isCreate(ConfigBuilder configBuilder, FileType fileType, String filePath) {
                // 判斷自定義文件夾是否需要?jiǎng)?chuàng)建
                checkDir("調(diào)用默認(rèn)方法創(chuàng)建的目錄,自定義目錄用");
                if (fileType == FileType.MAPPER) {
                    // 已經(jīng)生成 mapper 文件判斷存在,不想重新生成返回 false
                    return !new File(filePath).exists();
                }
                // 允許生成模板文件
                return true;
            }
        });
        */
        cfg.setFileOutConfigList(focList);
        mpg.setCfg(cfg);
        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();
        // 配置自定義輸出模板
        //指定自定義模板路徑,注意不要帶上.ftl/.vm, 會(huì)根據(jù)使用的模板引擎自動(dòng)識(shí)別
        // templateConfig.setEntity("templates/entity2.java");
        // templateConfig.setService();
        // templateConfig.setController();
        templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);
        // 策略配置
        StrategyConfig strategy = new StrategyConfig();
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
//        strategy.setSuperEntityClass("你自己的父類(lèi)實(shí)體,沒(méi)有就不用設(shè)置!");
        strategy.setEntityLombokModel(true);
        strategy.setRestControllerStyle(true);
        // 公共父類(lèi)
//        strategy.setSuperControllerClass("你自己的父類(lèi)控制器,沒(méi)有就不用設(shè)置!");
        // 寫(xiě)于父類(lèi)中的公共字段
        strategy.setSuperEntityColumns("id");
        strategy.setInclude(scanner("表名,多個(gè)英文逗號(hào)分割").split(","));
        strategy.setControllerMappingHyphenStyle(true);
        strategy.setTablePrefix(pc.getModuleName() + "_");
        mpg.setStrategy(strategy);
        mpg.setTemplateEngine(new FreemarkerTemplateEngine());
        mpg.execute();
    }
}

MybatisPlus代碼生成器,自用版本不帶xml

package com.wuyd.mybatispulsdemo;
import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.*;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
/**
 * @author wuyd
 * 創(chuàng)建時(shí)間:2019/10/8 11:17
 */
public class CodeGenerator {
    public static void main(String[] args) {
        AutoGenerator mpg = new AutoGenerator();
        //全局配置
        GlobalConfig gc = new GlobalConfig();
        gc.setOutputDir(System.getProperty("user.dir")+"/src/main/java");
        gc.setFileOverride(true);
        //不需要ActiveRecord特性的請(qǐng)改為false
        gc.setActiveRecord(true);
        gc.setSwagger2(true);
        gc.setAuthor("wuyd");
        //自定義文件命名,注意%s 會(huì)自動(dòng)填充表實(shí)體屬性
        gc.setControllerName("%sController");
        gc.setServiceName("%sService");
        gc.setServiceImplName("%sServiceImpl");
        gc.setEntityName("%sEntity");
        gc.setMapperName("%sMapper");
        mpg.setGlobalConfig(gc);
        //數(shù)據(jù)源配置
        DataSourceConfig dsc = new DataSourceConfig();
        dsc.setDbType(DbType.MYSQL);
        dsc.setDriverName("com.mysql.jdbc.Driver");
        dsc.setUsername("xxx");
        dsc.setPassword("xxx");
        dsc.setUrl("jdbc:mysql://xxx.xxx.xxx.xxx:3306/xxxxx?useUnicode=true&useSSL=false&characterEncoding=utf8");
        mpg.setDataSource(dsc);
        //策略配置
        StrategyConfig strategy = new StrategyConfig();
        //此處可以修改您的表前綴
        strategy.setTablePrefix(new String[]{});
        //表名生成策略
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);
        //需要生成的表
        strategy.setInclude(new String[]{"knapsacks","knapsacks_kind","knapsacks_prop","knapsacks_recharge_card"});
        strategy.setSuperServiceClass(null);
        strategy.setSuperServiceImplClass(null);
        strategy.setSuperMapperClass(null);
        strategy.setControllerMappingHyphenStyle(true);
        strategy.setEntityLombokModel(true);
        strategy.setEntitySerialVersionUID(true);
        strategy.setEntityTableFieldAnnotationEnable(true);
        mpg.setStrategy(strategy);
        // 配置模板
        TemplateConfig templateConfig = new TemplateConfig();
        templateConfig.setXml(null);
        mpg.setTemplate(templateConfig);
        //包配置
        PackageConfig pc = new PackageConfig();
        pc.setParent("com.wuyd.mybatispulsdemo");
        pc.setController("controller");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setMapper("mapper");
        pc.setEntity("entity");
        mpg.setPackageInfo(pc);
        //執(zhí)行生成
        mpg.execute();
    }
}

pom.xml

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.2.0</version>
        </dependency>
        <!-- ORM  選一款 -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>${mybatis-plus-boot-starter.version}</version>
        </dependency>
        <!-- Mysql驅(qū)動(dòng)  注意版本!-->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>${mysql-connector.version}</version>
        </dependency>
        <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.1</version>
        </dependency>

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Spring MVC實(shí)現(xiàn)mysql數(shù)據(jù)庫(kù)增刪改查完整實(shí)例

    Spring MVC實(shí)現(xiàn)mysql數(shù)據(jù)庫(kù)增刪改查完整實(shí)例

    這篇文章主要介紹了Spring MVC實(shí)現(xiàn)mysql數(shù)據(jù)庫(kù)增刪改查完整實(shí)例,從創(chuàng)建一個(gè)web項(xiàng)目開(kāi)始,分享了項(xiàng)目結(jié)構(gòu)以及具體Java代碼和前端頁(yè)面等相關(guān)內(nèi)容,具有一定借鑒價(jià)值,需要的朋友可以了解下。
    2017-12-12
  • 淺談Java數(shù)據(jù)結(jié)構(gòu)之稀疏數(shù)組知識(shí)總結(jié)

    淺談Java數(shù)據(jù)結(jié)構(gòu)之稀疏數(shù)組知識(shí)總結(jié)

    今天帶大家了解一下Java稀疏數(shù)組的相關(guān)知識(shí),文中有非常詳細(xì)的介紹及代碼示例,對(duì)正在學(xué)習(xí)java的小伙伴們有很好地幫助,需要的朋友可以參考下
    2021-05-05
  • Java實(shí)現(xiàn)LeetCode(組合總和)

    Java實(shí)現(xiàn)LeetCode(組合總和)

    這篇文章主要介紹了Java實(shí)現(xiàn)LeetCode(組合總數(shù)),本文通過(guò)使用java實(shí)現(xiàn)leetcode的組合總數(shù)題目和實(shí)現(xiàn)思路分析,需要的朋友可以參考下
    2021-06-06
  • maven的生命周期及常用命令介紹

    maven的生命周期及常用命令介紹

    maven是一個(gè)項(xiàng)目構(gòu)建和管理的工具,提供了幫助管理 構(gòu)建、文檔、報(bào)告、依賴(lài)、scms、發(fā)布、分發(fā)的方法。下面通過(guò)本文給大家分享maven的生命周期及常用命令介紹,需要的朋友參考下吧
    2017-11-11
  • Java函數(shù)式編程(四):在集合中查找元素

    Java函數(shù)式編程(四):在集合中查找元素

    這篇文章主要介紹了Java函數(shù)式編程(四):在集合中查找元素,本文是系列文章的第4篇,其它篇章請(qǐng)參閱相關(guān)文章,需要的朋友可以參考下
    2014-09-09
  • SpringBoot整合Echarts實(shí)現(xiàn)數(shù)據(jù)大屏

    SpringBoot整合Echarts實(shí)現(xiàn)數(shù)據(jù)大屏

    這篇文章給大家介紹了三步實(shí)現(xiàn)SpringBoot全局日志記錄,整合Echarts實(shí)現(xiàn)數(shù)據(jù)大屏,文中通過(guò)代碼示例給大家介紹的非常詳細(xì),具有一定的參考價(jià)值,需要的朋友可以參考下
    2024-03-03
  • 基于@RequestParam與@RequestBody使用對(duì)比

    基于@RequestParam與@RequestBody使用對(duì)比

    這篇文章主要介紹了@RequestParam與@RequestBody的使用對(duì)比,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-10-10
  • 如何利用Java獲取當(dāng)天的開(kāi)始和結(jié)束時(shí)間

    如何利用Java獲取當(dāng)天的開(kāi)始和結(jié)束時(shí)間

    這篇文章主要介紹了如何使用Java?8的LocalDate和LocalDateTime類(lèi)獲取指定日期的開(kāi)始和結(jié)束時(shí)間,展示了如何通過(guò)這些類(lèi)進(jìn)行日期和時(shí)間的處理,從而簡(jiǎn)化了日期時(shí)間操作,需要的朋友可以參考下
    2025-02-02
  • SpringBoot注冊(cè)Servlet的三種方法詳解

    SpringBoot注冊(cè)Servlet的三種方法詳解

    這篇文章主要介紹了SpringBoot注冊(cè)Servlet的三種方法詳解,教你如何Spring Boot 注冊(cè) Servlet、Filter、Listener,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2019-05-05
  • java中-jar 與nohup的對(duì)比

    java中-jar 與nohup的對(duì)比

    這篇文章主要介紹了java中 -jar 與nohup的對(duì)比的相關(guān)資料,需要的朋友可以參考下
    2017-05-05

最新評(píng)論

嘉荫县| 咸宁市| 韶关市| 石门县| 浏阳市| 始兴县| 来安县| 博爱县| 礼泉县| 镇巴县| 华容县| 平南县| 南靖县| 报价| 安龙县| 平凉市| 平罗县| 巴东县| 连南| 南岸区| 蕲春县| 阿合奇县| 巴中市| 松原市| 文登市| 汉沽区| 本溪市| 鄄城县| 郯城县| 郑州市| 阳山县| 庆安县| 姜堰市| 五河县| 天长市| 淄博市| 枞阳县| 财经| 永清县| 三门县| 梨树县|