Mybatis在IDEA中使用generator逆向工程產生pojo,mapper

來源:互聯網
上載者:User

標籤:local   block   soft   資料   菜單   splay   結構   --   rmi   

使用mybatis可以逆向產生pojo和mapper檔案有很多種方式,我以前用的是mybtais內建的generator包來產生,串連如下:mybatis自己產生pojo

今天我用了IDEA上使用maven項目來產生pojo和mapper,具體步驟如下

1,先配置pom.xml檔案,先配置外掛程式plugin

設定檔如下

    <build>        <plugins>            <!-- mybatis逆向工程 -->            <plugin>                <groupId>org.mybatis.generator</groupId>                <artifactId>mybatis-generator-maven-plugin</artifactId>                <version>1.3.2</version>                <configuration>                    <!--設定檔的位置-->                    <configurationFile>src/main/resources/Personal-GeneratorConfig.xml</configurationFile>                    <verbose>true</verbose>                    <overwrite>true</overwrite>                </configuration>              </plugin>         </plugins>    </build>

2,項目中添加設定檔,如上面所示的設定檔目錄位置,在添加personal-generatorconfig.xml檔案,然後添加設定檔personal-db.properties,位置結構:

 

其中personal-generator.xml的代碼如下

<?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>    <properties resource="Personal-DB.properties"></properties>    <classPathEntry location="${jdbc.driverLocation}" />    <!--classPathEntry location="D:\zngkpt\m2\repository\mysql\mysql-connector-java\5.1.40\mysql-connector-java-5.1.40.jar" /-->    <context id="context1" targetRuntime="MyBatis3">        <commentGenerator>            <!-- 去除自動產生的注釋 -->            <property name="suppressAllComments" value="true" />        </commentGenerator>                <!-- 資料庫連接配置 -->        <jdbcConnection driverClass="${jdbc.driverClass}"            connectionURL="${jdbc.connectionURL}"            userId="${jdbc.userId}"            password="${jdbc.password}" />        <!--jdbcConnection driverClass="com.mysql.jdbc.Driver"                        connectionURL="jdbc:mysql://localhost:3306/test"                        userId="root"                        password="mysql" /--> <!-- 非必需,類型處理器,在資料庫類型和java類型之間的轉換控制-->        <javaTypeResolver>            <property name="forceBigDecimals" value="false"/>        </javaTypeResolver>        <!--配置產生的實體包            targetPackage:產生的實體包位置,預設存放在src目錄下            targetProject:目標工程名         -->        <javaModelGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.pojo"            targetProject="src/main/java" />                    <!-- 實體包對應對應檔位置及名稱,預設存放在src目錄下 -->        <sqlMapGenerator targetPackage="com.unisits.zngkpt.common.userprivrman.mapper" targetProject="src/main/java" />        <!-- 配置表             schema:不用填寫            tableName: 表名            enableCountByExample、enableSelectByExample、enableDeleteByExample、enableUpdateByExample、selectByExampleQueryId:            去除自動產生的例子        -->        <table schema="" tableName="sys_role" enableCountByExample="false" enableSelectByExample="false"            enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>        <table schema="" tableName="sys_permission" enableCountByExample="false" enableSelectByExample="false"               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>        <table schema="" tableName="sys_role_permission" enableCountByExample="false" enableSelectByExample="false"               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>        <table schema="" tableName="sys_user" enableCountByExample="false" enableSelectByExample="false"               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>        <table schema="" tableName="sys_user_role" enableCountByExample="false" enableSelectByExample="false"        enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>        <table schema="" tableName="unit_info" enableCountByExample="false" enableSelectByExample="false"               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>        <table schema="" tableName="unit_type" enableCountByExample="false" enableSelectByExample="false"               enableDeleteByExample="false" enableUpdateByExample="false" selectByExampleQueryId="false" >        </table>    </context></generatorConfiguration>

personal-db.properties的代碼如下

jdbc.driverLocation=D:\\zngkpt\\m2\\repository\\com\\microsoft\\sqlserver\\sqljdbc4\\4.0\\sqljdbc4-4.0.jarjdbc.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriverjdbc.connectionURL=jdbc:sqlserver://127.0.0.1:1434;DatabaseName=db_zngkptjdbc.userId=sajdbc.password=123456

3,到現在為止,所有的mybatis配置工作已經結束了,開始配置idea來運行產生pojo吧

點擊菜單Run->Edit Configuration,然後在彈出表單的左上方,點擊+->maven,會出現下面表單

然後點擊apply,確定,然後run剛才建立的那個maven即可,最後產生的結構如下

 

Mybatis在IDEA中使用generator逆向工程產生pojo,mapper

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.