Mybatis Generator自動生成對應文件的實現(xiàn)方法
使用Generator自動生成我們需要的bean dao mapper xml等文件的過程(沒有借助eclipse等編輯工具直接命令提示符生成)
第一步:在E盤新建一個文件夾generator,在這文件夾下創(chuàng)建一個test文件夾用來存放生成的文件,在創(chuàng)建一個generator.xml的配置文件
第二步:導入需要的jar包 mybatis-generator-core-1.3.2.jar 和mysql-connector-java-5.1.28-bin.jar
第三步:編寫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> <!-- 數(shù)據(jù)庫驅(qū)動包位置 --> <classPathEntry location="E:\generator\mysql-connector-java-5.1.28-bin.jar" /> <!-- <classPathEntry location="C:\oracle\product\10.2.0\db_1\jdbc\lib\ojdbc14.jar" />--> <context id="DB2Tables" targetRuntime="MyBatis3"> <commentGenerator> <property name="suppressAllComments" value="true" /> </commentGenerator> <!-- 數(shù)據(jù)庫鏈接URL、用戶名、密碼 --> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://localhost/webdata?characterEncoding=utf8" userId="root" password="root"> <!--<jdbcConnection driverClass="oracle.jdbc.driver.OracleDriver" connectionURL="jdbc:oracle:thin:@localhost:1521:orcl" userId="msa" password="msa">--> </jdbcConnection> <!--java類型處理器 --> <javaTypeResolver> <property name="forceBigDecimals" value="false" /> </javaTypeResolver> <!-- 生成bean的包名和位置 targetPackage 存放的包名 targetProject項目名 --> <javaModelGenerator targetPackage="entity" targetProject="E:\generator\test"> <property name="enableSubPackages" value="true" /> <property name="trimStrings" value="true" /> </javaModelGenerator> <!-- 生成的映射文件包名和位置 --> <sqlMapGenerator targetPackage="mapper" targetProject="E:\generator\test"> <property name="enableSubPackages" value="true" /> </sqlMapGenerator> <!-- 生成DAO的包名和位置 --> <javaClientGenerator type="XMLMAPPER" targetPackage="dao" targetProject="E:\generator\test"> <property name="enableSubPackages" value="true" /> </javaClientGenerator> <!-- 要生成的表 tableName 表名 --> <table tableName="user" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> <table tableName="product" enableCountByExample="false" enableUpdateByExample="false" enableDeleteByExample="false" enableSelectByExample="false" selectByExampleQueryId="false" /> </context> </generatorConfiguration>
編寫完后
第四步:打開cmd命令提示行 進入到E盤generator目錄下 執(zhí)行
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
這樣就表示創(chuàng)建成功
自動幫我們創(chuàng)建了三個文件夾并把相應的java文件創(chuàng)建好了
創(chuàng)建我們編寫sql語句的mapper.xml文件
創(chuàng)建對應的實體類
創(chuàng)建對應的dao接口
總結(jié)
以上所述是小編給大家介紹的Mybatis Generator自動生成對應的文件的實現(xiàn)方法,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
相關文章
解決Mybatis-plus自定義TypeHandler查詢映射結(jié)果一直為null問題
這篇文章主要介紹了解決Mybatis-plus自定義TypeHandler查詢映射結(jié)果一直為null問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07帶你了解如何使用Spring基于ProxyFactoryBean創(chuàng)建AOP代理
這篇文章主要介紹了Spring基于ProxyFactoryBean創(chuàng)建AOP代理,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2021-08-08一文搞懂接口參數(shù)簽名與驗簽(附含java python php版)
這篇文章主要為大家介紹了java python php不同版的接口參數(shù)簽名與驗簽示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2023-06-06Java編程實現(xiàn)生成給定范圍內(nèi)不重復隨機數(shù)的方法小結(jié)
這篇文章主要介紹了Java編程實現(xiàn)生成給定范圍內(nèi)不重復隨機數(shù)的方法,結(jié)合實例形式總結(jié)分析了java基于數(shù)學運算與判斷實現(xiàn)不重復隨機數(shù)的生成功能,需要的朋友可以參考下2017-07-07解讀List?list=new?ArrayList()是怎么回事
這篇文章主要介紹了解讀List?list=new?ArrayList()是怎么回事,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-06-06