首页 > 其他 > 详细

mybatis-plus 逆向工程模板

时间:2020-05-18 21:45:17      阅读:261      评论:0      收藏:0      [点我收藏+]

mybatis-plus 逆向工程模板

@Test
public void generator(){
    //项目路径
    System.out.println(System.getProperty("user.dir"));

    //代码生成器
    AutoGenerator autoGenerator = new AutoGenerator();
    //全局配置 调用generator.config下的
    GlobalConfig gc = new GlobalConfig();
    //获取当前项目的路径
    String path = System.getProperty("user.dir");
    //设置是否开启AR
    gc.setActiveRecord(true)
            .setAuthor("chz")
            //文件输出路径
            .setOutputDir(path+"/src/main/java")
            //是否覆盖文件
            .setFileOverride(true)
            //设置主键自增策略
            .setIdType(IdType.AUTO)
            //是否开启resultMap,默认false
            .setBaseResultMap(true)
            //是否开启sql片段,默认false
            .setBaseColumnList(true);


    //数据源配置
    DataSourceConfig dataSourceConfig = new DataSourceConfig();
    dataSourceConfig.setDbType(DbType.MYSQL)
            .setDriverName("com.mysql.cj.jdbc.Driver")
            .setUrl("jdbc:mysql://localhost:3306/mp?userSSL=false&serverTimezone=Asia/Shanghai")
            .setUsername("root")
            .setPassword("12345");

    //策略配置
    StrategyConfig strategyConfig = new StrategyConfig();
    //是否开启大写命名,默认不开启
    strategyConfig.setCapitalMode(false)
            //数据库表映射到实体类命名策略
            .setNaming(NamingStrategy.underline_to_camel)
            //设置想要生成的表
            .setInclude("tbl_employee")
            //生成的dao,service,entity不再带tbl_前缀
            .setTablePrefix("tbl_");


    //包配置
    PackageConfig packageConfig = new PackageConfig();
    //setParent设置统一的包路径
    packageConfig.setParent("com.chz")
            .setMapper("mapper")
            .setService("service")
            .setController("controller")
            .setEntity("entity")
            .setXml("mapper");

    //整合配置
    autoGenerator.setPackageInfo(packageConfig)
            .setDataSource(dataSourceConfig)
            .setGlobalConfig(gc)
            .setStrategy(strategyConfig);
    //执行
    autoGenerator.execute();
}

mybatis-plus 逆向工程模板

原文:https://www.cnblogs.com/kikochz/p/12912890.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!