Skip to content

Commit 69df5c0

Browse files
author
汪涛
committed
feat: 添加MybatisPlus代码生成器相关配置
添加了MybatisPlus代码生成器相关配置,包括输出文件类型、输出位置、模板名称等信息,以及实体、Mapper、Service和Controller等策略配置。同时,添加了MybatisPlus代码生成器UI的启动代码和读取配置文件的方法。
1 parent 3699689 commit 69df5c0

File tree

3 files changed

+162
-0
lines changed

3 files changed

+162
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# mybatis-plus-generate-UI配置文件
2+
jdbc.url=jdbc:mysql://192.168.6.230:3306/ai_chat
3+
jdbc.username=tacrux
4+
jdbc.password=sadf%qweTGYUU1
5+
jdbc.driverClassName=com.mysql.cj.jdbc.Driver
6+
basePackage=cn.trve.example
7+
port=8068
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
{
2+
"outputFiles": [
3+
{
4+
"fileType": "Entity",
5+
"outputLocation": "cn.trve.1example.entity",
6+
"templateName": "entity.java.btl",
7+
"templatePath": null,
8+
"builtIn": true,
9+
"outputPackage": "cn.trve.example.entity"
10+
},
11+
{
12+
"fileType": "Mapper.xml",
13+
"outputLocation": "resources:mapper",
14+
"templateName": "mapper.xml.btl",
15+
"templatePath": null,
16+
"builtIn": true,
17+
"outputPackage": "mapper"
18+
},
19+
{
20+
"fileType": "Mapper.java",
21+
"outputLocation": "cn.trve.example.mapper",
22+
"templateName": "mapper.java.btl",
23+
"templatePath": null,
24+
"builtIn": true,
25+
"outputPackage": "cn.trve.example.mapper"
26+
},
27+
{
28+
"fileType": "Service",
29+
"outputLocation": "cn.trve.example.service",
30+
"templateName": "service.java.btl",
31+
"templatePath": null,
32+
"builtIn": true,
33+
"outputPackage": "cn.trve.example.service"
34+
},
35+
{
36+
"fileType": "ServiceImpl",
37+
"outputLocation": "cn.trve.example.service.impl",
38+
"templateName": "serviceimpl.java.btl",
39+
"templatePath": null,
40+
"builtIn": true,
41+
"outputPackage": "cn.trve.example.service.impl"
42+
},
43+
{
44+
"fileType": "Controller",
45+
"outputLocation": "cn.trve.example.controller",
46+
"templateName": "controller.java.btl",
47+
"templatePath": null,
48+
"builtIn": true,
49+
"outputPackage": "cn.trve.example.controller"
50+
}
51+
],
52+
"entityStrategy": {
53+
"superEntityClass": "cn.trve.framework.db.model.Entity",
54+
"superEntityColumns": [
55+
"id",
56+
"createDate",
57+
"createBy",
58+
"lastModifiedDate",
59+
"lastModifiedBy",
60+
"version",
61+
"deleted"
62+
],
63+
"tableFills": null,
64+
"entitySerialVersionUID": true,
65+
"entityColumnConstant": false,
66+
"activeRecord": true,
67+
"entityBuilderModel": false,
68+
"entityLombokModel": false,
69+
"entityBooleanColumnRemoveIsPrefix": false,
70+
"entityTableFieldAnnotationEnable": false,
71+
"versionFieldName": null,
72+
"logicDeleteFieldName": null,
73+
"swagger2": false
74+
},
75+
"mapperStrategy": {
76+
"superMapperClass": "com.baomidou.mybatisplus.core.mapper.BaseMapper"
77+
},
78+
"mapperXmlStrategy": {
79+
"baseResultMap": false,
80+
"enableCache": false
81+
},
82+
"controllerStrategy": {
83+
"superControllerClass": null,
84+
"restControllerStyle": false,
85+
"controllerMappingHyphenStyle": false
86+
},
87+
"serviceStrategy": {
88+
"superServiceClass": "com.baomidou.mybatisplus.extension.service.IService"
89+
},
90+
"serviceImplStrategy": {
91+
"superServiceImplClass": "com.baomidou.mybatisplus.extension.service.impl.ServiceImpl"
92+
}
93+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package db;
2+
3+
import com.github.davidfantasy.mybatisplus.generatorui.GeneratorConfig;
4+
import com.github.davidfantasy.mybatisplus.generatorui.MybatisPlusToolsApplication;
5+
import com.github.davidfantasy.mybatisplus.generatorui.mbp.NameConverter;
6+
7+
import java.io.IOException;
8+
import java.io.InputStream;
9+
import java.util.Properties;
10+
11+
public class GeneratorUIServer {
12+
13+
public static void main(String[] args) {
14+
GeneratorConfig generatorConfig = readProp();
15+
MybatisPlusToolsApplication.run(generatorConfig);
16+
System.out.println(String.format(
17+
"""
18+
当前数据库连接信息:%s
19+
当前库名:%s
20+
MybatisPlus代码生成器启动成功,访问地址:http://localhost:%s
21+
""",
22+
generatorConfig.getJdbcUrl(),
23+
generatorConfig.getSchemaName(),
24+
generatorConfig.getPort()));
25+
}
26+
27+
28+
/**
29+
* 从配置文件中读取配置.
30+
* 路径为:/db/mbg.properties
31+
*/
32+
private static GeneratorConfig readProp() {
33+
InputStream is = GeneratorUIServer.class.getResourceAsStream("/db/mbg/mbg.properties");
34+
Properties prop = new Properties();
35+
try {
36+
prop.load(is);
37+
} catch (IOException e) {
38+
throw new RuntimeException("读取配置文件失败", e);
39+
}
40+
String jdbcUrl = prop.getProperty("jdbc.url", "jdbc:mysql://localhost:3306/example");
41+
GeneratorConfig config = GeneratorConfig.builder()
42+
.jdbcUrl(jdbcUrl)
43+
.userName(prop.getProperty("jdbc.username", "root"))
44+
.password(prop.getProperty("jdbc.password", "root"))
45+
.driverClassName(prop.getProperty("jdbc.driverClassName", "com.mysql.cj.jdbc.Driver"))
46+
//数据库schema,MSSQL,PGSQL,ORACLE,DB2类型的数据库需要指定
47+
.schemaName(prop.getProperty("jdbc.url", jdbcUrl).split("/")[3])
48+
.basePackage(prop.getProperty("basePackage", "cn.trve.example"))
49+
.port(Integer.parseInt(prop.getProperty("port", "8068")))
50+
.nameConverter(new NameConverter() {
51+
@Override
52+
public String serviceNameConvert(String entityName) {
53+
return entityName + "Service";
54+
}
55+
})
56+
.build();
57+
58+
return config;
59+
}
60+
61+
62+
}

0 commit comments

Comments
 (0)