首先,在pom.xml中配置generator 插件所对应的配置文件 ${basedir}/src/main/resources/generator/generatorConfig.xml
接下来是所需要的generatorConfig.xml,项目中位置如下:
generatorConfig.xml文件内容如下:
1 <?xml version="1.0" encoding="UTF-8" ?>
2
3
4
5
6
7
9
10
11
12
13
14
15
16
17
18 connectionURL="jdbc:mysql://localhost:3306/数据库名?useUnicode=true&characterEncoding=utf8&rewriteBatchedStatements=TRUE"
19 userId="root" password="admin" />
20
21
22
23
24
25
26
27 targetProject="src\main\java">
28
29
30
31
32
33
34 targetProject="src\main\resources">
35
36
37
38
39 targetProject="src\main\java" type="XMLMAPPER">
40
41
42
43
44
45 domainObjectName="实体类名" enableCountByExample="false"
46 enableUpdateByExample="false" enableDeleteByExample="false"
47 enableSelectByExample="false" selectByExampleQueryId="false">
48
49
50
点击IDEA上的run ==》Edit Configurations:
然后配置generator:
然后运行此插件:
注意同一张表一定不要运行多次,因为mapper的映射文件中会生成多次的代码,会导致导致报错,运行之后项目目录结构为:
至此 实体类,实体类接口,sql文件都已生成。