IDEA中使用MyBatis Generator

1.使用

如下主要介绍在IDEA 中使用MyBatis Generator 更多想使用请参考官网: http://www.mybatis.org/generator/
1. 新建一个Maven 项目在POM中添加

 <build>
       <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.6</version>
                <configuration>
                  <!--配置文件的位置-->
                    <configurationFile>src/main/resources/generator/generatorConfig.xml</configurationFile>
                    <verbose>true</verbose>
                    <overwrite>true</overwrite>
                </configuration>
                <executions>
                    <execution>
                        <id>Generate MyBatis Artifacts</id>
                        <goals>
                            <goal>generate</goal>
                        </goals>
                    </execution>
                </executions>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.6</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
    </build>
  1. 新建generatorConfig.xml 配置内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "mybatis-generator-config_1_0.dtd">

<generatorConfiguration>
    <!--本地数据库驱动-->
    <classPathEntry location="E:\.m2\repository\mysql\mysql-connector-java\6.0.6\mysql-connector-java-6.0.6.jar"/>
    <context id="MysqlTables" targetRuntime="MyBatis3">
        <!--去除注释  -->
        <commentGenerator>
            <property name="suppressAllComments" value="true"/>
        </commentGenerator>

        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/junli?useUnicode=true&amp;characterEncoding=utf-8&amp;useSSL=false&amp;useJDBCCompliantTimezoneShift=true&amp;useLegacyDatetimeCode=false&amp;serverTimezone=UTC"
                        userId="root"
                        password="123456">
        </jdbcConnection>

        <javaTypeResolver>
            <property name="forceBigDecimals" value="false"/>
        </javaTypeResolver>

        <!--实体存放位置-->
        <javaModelGenerator targetPackage="com.junly.mybatis.beans"
                            targetProject="G:\learnworkspace\learn-mybatis\src\main\java">
            <property name="enableSubPackages" value="true"/>
            <property name="trimStrings" value="true"/>
        </javaModelGenerator>

        <!--XML存放位置-->
        <sqlMapGenerator targetPackage="xml" targetProject="G:\learnworkspace\learn-mybatis\src\main\resources">
            <property name="enableSubPackages" value="true"/>
        </sqlMapGenerator>

        <!--Mapper存放位置-->
        <javaClientGenerator type="XMLMAPPER" targetPackage="com.junly.mybatis.mapper"
                             targetProject="G:\learnworkspace\learn-mybatis\\src\main\java">
            <property name="enableSubPackages" value="true"/>
        </javaClientGenerator>

         <!--需要生成的表-->
        <table schema="junli" tableName="posts" domainObjectName="Posts">
            <property name="useActualColumnNames" value="false"/>
        </table>
        <table schema="junli" tableName="test" domainObjectName="Test">
            <property name="useActualColumnNames" value="false"/>
        </table>
        <table schema="junli" tableName="blog" domainObjectName="Blog">
            <property name="useActualColumnNames" value="false"/>
        </table>

        <table schema="junli" tableName="author" domainObjectName="Author">
            <property name="useActualColumnNames" value="false"/>
        </table>

    </context>
</generatorConfiguration>
  1. 生成代码
    在完成以上两步之后。就会在idea中看到:直接点击mybatis-generator:generate就可生成。
    这里写图片描述

转载于:https://www.cnblogs.com/mokingone/p/9109003.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值