mybatis-plus 代码生成器

mybatis-plus 代码生成器

  • 随着反复编写代码而已,键盘上的c键和v键也早已渐渐模糊。记录一下mybatis-plus的代码生成器
  		<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-generator</artifactId>
            <version>3.3.0</version>
        </dependency>
         <dependency>
            <groupId>org.apache.velocity</groupId>
            <artifactId>velocity-engine-core</artifactId>
            <version>2.0</version>
        </dependency>
/**
 *  @author: cx
 *  @Date: 2021/11/09
 *  @Description: MP自动生成
 */
public class CodeGeneration {

    //main函数
    public static void main(String[] args) {

        AutoGenerator autoGenerator = new AutoGenerator();

        //全局配置
        GlobalConfig globalConfig = new GlobalConfig();
        globalConfig.setDateType(DateType.ONLY_DATE);
        //得到当前项目的路径
        //String oPath = System.getProperty("user.dir");

        //生成文件输出根目录
        globalConfig.setOutputDir("D:\\demo\\src\\main\\java");
        //生成完成后不弹出文件框
        globalConfig.setOpen(false);

        //文件覆盖
        globalConfig.setFileOverride(true);

        // 不需要ActiveRecord特性的请改为false
        globalConfig.setActiveRecord(false);

        // XML 二级缓存
        globalConfig.setEnableCache(false);

        // XML ResultMap
        globalConfig.setBaseResultMap(true);

        // XML columList
        globalConfig.setBaseColumnList(false);

        // 涉資作者
        globalConfig.setAuthor("czx");

        // 自定义文件命名,注意 %s 会自动填充表实体属性!
        globalConfig.setControllerName("%sController");
        globalConfig.setServiceName("I%sService");
        globalConfig.setServiceImplName("%sServiceImpl");
        globalConfig.setMapperName("%sMapper");
        globalConfig.setXmlName("%sMapper");
        globalConfig.setEntityName("%s");
        autoGenerator.setGlobalConfig(globalConfig);

        // 数据源配置
        DataSourceConfig config = new DataSourceConfig();

        //设置数据库类型
        config.setDbType(DbType.MYSQL);


        config.setDriverName("com.mysql.cj.jdbc.Driver");

        //用户名
        config.setUsername("xc");

        //密码
        config.setPassword("xc");

        //指定数据库
        config.setUrl("jdbc:mysql://你的数据库地址/数据库名?useSSL=false&serverTimezone=Asia/Shanghai");
        autoGenerator.setDataSource(config);

        // 策略配置
        StrategyConfig strategy = new StrategyConfig();

        // 表名生成策略
        strategy.setNaming(NamingStrategy.underline_to_camel);
        strategy.setColumnNaming(NamingStrategy.underline_to_camel);

        // 需要生成的表
        String[] names = {"user"};
        strategy.setInclude(names);
        strategy.setSuperServiceClass(null);
        strategy.setSuperServiceImplClass(null);
        strategy.setSuperMapperClass(null);
        strategy.setEntityLombokModel(true);

        去除表前缀
        //strategy.setTablePrefix("xc_");
        去除字段前缀
        //strategy.setFieldPrefix("");
        autoGenerator.setStrategy(strategy);

        // 包配置
        PackageConfig pc = new PackageConfig();
        //父包路径
        pc.setParent("com.tb.timebest_center");
        pc.setController("controller");
        pc.setService("service");
        pc.setServiceImpl("service.impl");
        pc.setMapper("dao");
        pc.setEntity("pojo.entity");
        pc.setXml("mapper");
        autoGenerator.setPackageInfo(pc);
        // 执行生成
        autoGenerator.execute();
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值