idea实现自动sql-generator的使用

1.实现步骤:
  9.1 加载插件

<build>
        <plugins>
            <plugin>
                <groupId>org.mybatis.generator</groupId>
                <artifactId>mybatis-generator-maven-plugin</artifactId>
                <version>1.3.5</version>
                <configuration>
                    <!--配置文件的路径-->
                    <configurationFile>src/main/resources/generatorConfig.xml</configurationFile>
                    <overwrite>true</overwrite>
                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>org.mybatis.generator</groupId>
                        <artifactId>mybatis-generator-core</artifactId>
                        <version>1.3.5</version>
                    </dependency>
                </dependencies>
            </plugin>
        </plugins>
  </build>

 9.2 设置配置文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE generatorConfiguration
        PUBLIC "-//mybatis.org//DTD MyBatis Generator Configuration 1.0//EN"
        "http://mybatis.org/dtd/mybatis-generator-config_1_0.dtd">

<!-- 配置生成器 -->
<generatorConfiguration>
    <!--数据库驱动jar -->
    <classPathEntry
            location="F:\1000phone\jar\mysql驱动\mysql-connector-java-5.0.8-bin.jar" />

    <context id="MyBatis" targetRuntime="MyBatis3">

        <!--去除注释 -->
        <commentGenerator>
            <property name="suppressAllComments" value="true" />
        </commentGenerator>

        <!--数据库连接 -->
        <jdbcConnection driverClass="com.mysql.jdbc.Driver"
                        connectionURL="jdbc:mysql://localhost:3306/chaoshi"
                        userId="root"
                        password="123456">
        </jdbcConnection>

        <!--生成实体类 指定包名 以及生成的地址 (可以自定义地址,但是路径不存在不会自动创建
        使用Maven生成在target目录下,会自动创建) -->
        <javaModelGenerator targetPackage="com.qf.bean"
                            targetProject="F:\1000phone\three\workspace\mybatis_0929\src\main\java">
            <property name="trimStrings" value="true" />
        </javaModelGenerator>


        <!--生成SQLmapper文件 -->
        <sqlMapGenerator targetPackage="mapper"
                         targetProject="F:\1000phone\three\workspace\mybatis_0929\src\main\resources">
        </sqlMapGenerator>
        <!--生成Dao文件,生成接口 -->
        <javaClientGenerator type="XMLMAPPER"
                             targetPackage="com.qf.dao"
                             targetProject="F:\1000phone\three\workspace\mybatis_0929\src\main\java">
        </javaClientGenerator>


        <table tableName="student" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
        </table>
      <table tableName="grade" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
        </table>
       <table tableName="subject" enableCountByExample="false"
               enableUpdateByExample="false" enableDeleteByExample="false"
               enableSelectByExample="false" selectByExampleQueryId="false">
        </table>

    </context>
</generatorConfiguration>

9.3运行:maven Project选项卡->plugins->找到mybatis-generator-core,双击运行就会自动生成

猜你喜欢

转载自www.cnblogs.com/yunshao/p/9949370.html