1. 程式人生 > >idea實現自動sql-generator的使用

idea實現自動sql-generator的使用

text value 文件 sources ring tar lec word space

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,雙擊運行就會自動生成

idea實現自動sql-generator的使用