-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGeneratorServiceEntity.java
68 lines (63 loc) · 2.71 KB
/
GeneratorServiceEntity.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
package com.hqx.site;
import com.baomidou.mybatisplus.generator.AutoGenerator;
import com.baomidou.mybatisplus.generator.config.DataSourceConfig;
import com.baomidou.mybatisplus.generator.config.GlobalConfig;
import com.baomidou.mybatisplus.generator.config.PackageConfig;
import com.baomidou.mybatisplus.generator.config.StrategyConfig;
import com.baomidou.mybatisplus.generator.config.rules.DbType;
import com.baomidou.mybatisplus.generator.config.rules.NamingStrategy;
import org.junit.jupiter.api.Test;
/**
* Created by LiuLP on 2019/3/29.
*/
public class GeneratorServiceEntity {
@Test
public void generateCode() {
String packageName = "com.hqx.site";
//user -> UserDao, 设置成true: user -> IUserService
boolean serviceNameStartWithI = false;
generateByTables(serviceNameStartWithI, packageName,
"t_fault_record");
}
private void generateByTables(boolean serviceNameStartWithI, String packageName, String... tableNames) {
GlobalConfig config = new GlobalConfig();
String dbUrl = "jdbc:mysql://192.168.2.190:3306/procp20180003";
DataSourceConfig dataSourceConfig = new DataSourceConfig();
dataSourceConfig.setDbType(DbType.MYSQL)
.setUrl(dbUrl)
.setUsername("root")
.setPassword("hqxkj168++")
.setDriverName("com.mysql.jdbc.Driver");
StrategyConfig strategyConfig = new StrategyConfig();
strategyConfig
.setCapitalMode(true)
.setEntityLombokModel(true)
.setDbColumnUnderline(true)
.setNaming(NamingStrategy.underline_to_camel)
//修改替换成你需要的表名,多个表名传数组
.setInclude(tableNames)
// 此处可以修改为您的表前缀
.setTablePrefix(new String[]{"t_"});
config.setActiveRecord(false)
.setAuthor("LXG")
.setOutputDir("D:\\idea_workspace\\PROCP20180003\\site\\src\\main\\java")
.setFileOverride(false);
if (!serviceNameStartWithI) {
config.setServiceName("%sService");
}
// XML 二级缓存
config.setEnableCache(false);
// XML ResultMap
config.setBaseResultMap(false);
// XML columList
config.setBaseColumnList(false);
new AutoGenerator().setGlobalConfig(config)
.setDataSource(dataSourceConfig)
.setStrategy(strategyConfig)
.setPackageInfo(
new PackageConfig()
.setParent(packageName)
.setEntity("model")
).execute();
}
}