原创

Mybatis代码自动生成插件使用

版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://daichen.blog.csdn.net/article/details/14140489

1.配置pom.xml

添加mybatis-generator-maven-plugin到pom.xml。

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
<?xml version="1.0" encoding="UTF-8"?>
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    <parent>
        <artifactId>orm</artifactId>
        <groupId>com.cdai.demo</groupId>
        <version>1.0-SNAPSHOT</version>
    </parent>
    <modelVersion>4.0.0</modelVersion>
 
    <artifactId>mybatis-generator</artifactId>
 
    <dependencies>
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.9</version>
        </dependency>
    </dependencies>
 
    <build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.2</version>
                <configuration>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
            </plugin>
        </plugins>
    </build>
 
</project>



2.插件配置文件

插件配置文件默认读取src/main/resources/generatorConfig.xml

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
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
 
<generatorConfiguration>
    <classPathEntry location="C:\Users\cdai\.m2\repository\mysql\mysql-connector-java\5.1.9\mysql-connector-java-5.1.9.jar" />
 
    <context id="Test" targetRuntime="MyBatis3">
 
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://192.168.1.100:3306/demo?generateSimpleParameterMetadata=true"
                        userId="root"
                        password="">
        </jdbcConnection>
 
        <javaTypeResolver >
            <property name="forceBigDecimals" value="false" />
        </javaTypeResolver>
 
        <!-- generate Model -->
        <javaModelGenerator targetPackage="com.cdai.demo.orm.mybatis" targetProject="D:\ideaspaces\demo\orm\mybatis-generator\src\main\java">
            <property name="enableSubPackages" value="true" />
            <property name="trimStrings" value="true" />
        </javaModelGenerator>
 
        <!-- generate xml -->
        <sqlMapGenerator targetPackage="com.cdai.demo.orm.mybatis"  targetProject="D:\ideaspaces\demo\orm\mybatis-generator\src\main\resources">
            <property name="enableSubPackages" value="true" />
        </sqlMapGenerator>
 
        <!-- generate Mapper -->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.cdai.demo.orm.mybatis"  targetProject="D:\ideaspaces\demo\orm\mybatis-generator\src\main\java">
            <property name="enableSubPackages" value="true" />
        </javaClientGenerator>
 
        <table schema="" tableName="account" domainObjectName="Account"></table>
 
    </context>
 
</generatorConfiguration>



3.运行插件

运行代码生成插件的Maven任务:


生成代码:


文章最后发布于: 2013-11-04 21:16:49
展开阅读全文
0 个人打赏

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 编程工作室 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览