栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Mybatis-plus generator 3.5版本配置

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mybatis-plus generator 3.5版本配置

Mybatis-plus generator在3.5版本之后,发生了很大的变化。目前网上的文章大多是针对之前的版本,新版的使用说明相对较少,最近在工作中的使用情况记录一下,提供一种思路。

引入POM文件


     com.baomidou
     mybatis-plus-generator
     3.5.1



     com.baomidou
     mybatis-plus-annotation
     3.5.0
     compile

3.5版本中大量使用了build的设计模式,所有配置的创建都需要推过builder进行构建。在新版本中代码的生成策略也有很大的变化,使用起来更加方便了,可以指定生成代码的后缀,给生成类添加相应的注解。

    public static void main(String[] args) {
        //当前项目路径
        String projectPath = System.getProperty("user.dir");

        // 数据源
        DataSourceConfig dataSourceConfig = configDataSource();

        // 代码生成器
        AutoGenerator generator = new AutoGenerator(dataSourceConfig);

        // 全局配置
        GlobalConfig globalConfig = configGlobal(projectPath);
        generator.global(globalConfig);
        StrategyConfig strategyConfig = new StrategyConfig.Builder()
                .entityBuilder()
                .formatFileName("%sEntity")//添加后缀
                .enableLombok()//添加lombock的getter、setter注解
                .mapperBuilder()//mapper类添加@Mapper
                .enableMapperAnnotation()
                .build();

        generator.strategy(strategyConfig);

        // package config
        PackageConfig pkgConfig = new PackageConfig.Builder()
                .parent("com.sftz")
                .moduleName("gen")
                .entity("entity")
                .service("service")
                .serviceImpl("service.impl")
                .mapper("mapper")
                .xml("mapper.xml")
                .controller("controller")
                .other("other")
                .pathInfo(Collections.singletonMap(OutputFile.mapperXml, "E:\work-shop\workspace-sftz\mysql-entity-gen\src\main\resources\mapper"))
                .build();

        generator.packageInfo(pkgConfig) ;


        generator.execute();

    }

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/778616.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号