代码生成器使用
然后在idea控制台中执行以下命令:
cd application-demo(根据实际项目名称修改)
mvn exec:java
依次输入代码生成选项:
请输入子项目名称(填空表示生成代码到当前项目):(注意:虽然代码生成器在application-demo子项目中,但是它也可以将代码生成到其它的子项目中去!)
请输入模块名:DEMO(代码将生成到demo模块目录中,对应表DEMO_TEST的前缀DEMO,代码生成时会转成小写demo生成包名)
请输入表名:DEMO_TEST(数据库表名,DEMO代表服务模块前缀,TEST代表模块DEMO中的表TEST。代码生成时支持通过逗号分隔一次生成多张表,例如输入:DEMO_USER,DEMO_ORG将会一次生成这2张表对应的代码)
注意:重新执行命令不会覆盖已有文件,会跳过已有文件。必须先删除原文件再重新执行代码生成命令!
按照下图位置可以修改代码生成器连接的数据库信息:
数据库配置项如下所示,需要按照实际情况修改以下每项systemProperty的参数值:
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
69
70
71
72
73
<configuration>
<mainClass>com.framework.backend.CodeGenerator</mainClass>
<includeProjectDependencies>true</includeProjectDependencies>
<daemonThreadJoinTimeout>-1</daemonThreadJoinTimeout>
<!-- DM8数据库配置 start-->
<classpathScope>compile</classpathScope>
<systemProperties>
<systemProperty>
<!-- 数据库连接URL -->
<key>url</key>
<value>
jdbc:dm://xxx:xxx/BACKEND_FRAMEWORK_TEMPLATE?zeroDateTimeBehavior=convertToNull&useUnicode=true&characterEncoding=utf-8&schema=BACKEND_FRAMEWORK_TEMPLATE
</value>
</systemProperty>
<systemProperty>
<!-- 数据库账号名 -->
<key>username</key>
<value>xxx</value>
</systemProperty>
<systemProperty>
<!-- 数据库账号密码 -->
<key>password</key>
<value>xxx</value>
</systemProperty>
<systemProperty>
<!-- 数据库驱动类名 -->
<key>driverClassName</key>
<value>dm.jdbc.driver.DmDriver</value>
</systemProperty>
<systemProperty>
<!-- 数据库模式名 -->
<key>schema</key>
<value>BACKEND_FRAMEWORK_TEMPLATE</value>
</systemProperty>
<systemProperty>
<!-- 数据库类型 -->
<key>dbType</key>
<value>dm</value>
</systemProperty>
</systemProperties>
<!-- DM8数据库配置 end-->
<!-- MySQL8数据库配置 start-->
<!-- <classpathScope>runtime</classpathScope>-->
<!-- <systemProperties>-->
<!-- <systemProperty>-->
<!-- <key>url</key>-->
<!-- <value>-->
<!-- jdbc:mysql://xxx:xxx/xxx?characterEncoding=UTF-8-->
<!-- </value>-->
<!-- </systemProperty>-->
<!-- <systemProperty>-->
<!-- <key>username</key>-->
<!-- <value>xxx</value>-->
<!-- </systemProperty>-->
<!-- <systemProperty>-->
<!-- <key>password</key>-->
<!-- <value>xxx</value>-->
<!-- </systemProperty>-->
<!-- <systemProperty>-->
<!-- <key>driverClassName</key>-->
<!-- <value>com.mysql.cj.jdbc.Driver</value>-->
<!-- </systemProperty>-->
<!-- <systemProperty>-->
<!-- <key>schema</key>-->
<!-- <value>xxx</value>-->
<!-- </systemProperty>-->
<!-- <systemProperty>-->
<!-- <key>dbType</key>-->
<!-- <value>mysql</value>-->
<!-- </systemProperty>-->
<!-- </systemProperties>-->
<!-- MySQL8数据库配置 end-->
</configuration>
本文由作者按照
CC BY 4.0
进行授权