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 }

 

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

上一篇:Android 6.0源码编译及烧录到真机过程记录


下一篇:移动端布局