• mybatis-plus-generator: 自动生成entity,mapper,service,controller的代码


    //首先加入依赖
     
    <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-boot-starter</artifactId>
    <version>3.3.1.tmp</version>
    </dependency>
     
    <dependency>
    <groupId>com.baomidou</groupId>
    <artifactId>mybatis-plus-generator</artifactId>
    <version>3.3.1.tmp</version>
    </dependency>
     
    <dependency>
    <groupId>org.apache.velocity</groupId>
    <artifactId>velocity</artifactId>
    <version>1.7</version>
    </dependency>
     
     
    //然后写个main方法直接运行
     1 //mybatisplus 逆向工程 自动生成代码
     2 public class Main {
     3     public static void main(String[] args) {
     4         AutoGenerator autoGenerator = new AutoGenerator();
     5         //数据源
     6         DataSourceConfig dataSourceConfig = new DataSourceConfig();
     7         dataSourceConfig.setDbType(DbType.MYSQL);
     8         dataSourceConfig.setDriverName("com.mysql.cj.jdbc.Driver");
     9         dataSourceConfig.setUrl("jdbc:mysql://localhost:3306/test?useSSL=false&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&serverTimezone=GMT%2B8");
    10         dataSourceConfig.setUsername("root");
    11         dataSourceConfig.setPassword("root");
    12         autoGenerator.setDataSource(dataSourceConfig);
    13         //全局配置
    14         GlobalConfig globalConfig = new GlobalConfig();
    15         globalConfig.setOutputDir(System.getProperty("user.dir")+"/src/main/java");
    16         globalConfig.setOpen(false);
    17         globalConfig.setAuthor("daiwenxiang");
    18         globalConfig.setServiceName("%sService");
    19         autoGenerator.setGlobalConfig(globalConfig);
    20         PackageConfig packageConfig = new PackageConfig();
    21         packageConfig.setParent("com.example.mybatisplusdemo");
    22         packageConfig.setModuleName("generator");
    23         packageConfig.setController("controller");
    24         packageConfig.setService("service");
    25         packageConfig.setServiceImpl("service.impl");
    26         packageConfig.setMapper("mapper");
    27         packageConfig.setEntity("entity");
    28         autoGenerator.setPackageInfo(packageConfig);
    29         //配置策略
    30         StrategyConfig strategyConfig = new StrategyConfig();
    31         strategyConfig.setEntityLombokModel(true);
    32         strategyConfig.setNaming(NamingStrategy.underline_to_camel);
    33         strategyConfig.setColumnNaming(NamingStrategy.underline_to_camel);
    34         autoGenerator.setStrategy(strategyConfig);
    35         //执行
    36         autoGenerator.execute();
    37     }
    38 }

  • 相关阅读:
    Linux查看文件被哪个进程占用
    命令行启动rstudio server
    Spring Boot配置文件及多环境配置
    Spring Boot yml配置文件
    js实现自定义概率抽奖算法
    Flutter之adb: failed to install apk的解决方法
    Flutter之不简单的搜索条
    git操作之commit规范
    Flutter之毛玻璃效果的实现
    固定定位下div水平居中
  • 原文地址:https://www.cnblogs.com/daiwenxiang/p/12906862.html
Copyright © 2020-2023  润新知