使用Generator自動(dòng)生成我們需要的bean dao mapper xml等文件的過程(沒有借助eclipse等編輯工具直接命令提示符生成)
創(chuàng)新互聯(lián)是一家專業(yè)提供順昌企業(yè)網(wǎng)站建設(shè),專注與做網(wǎng)站、網(wǎng)站制作、html5、小程序制作等業(yè)務(wù)。10年已為順昌眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進(jìn)行中。
第一步:在E盤新建一個(gè)文件夾generator,在這文件夾下創(chuàng)建一個(gè)test文件夾用來存放生成的文件,在創(chuàng)建一個(gè)generator.xml的配置文件
第二步:導(dǎo)入需要的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ū)動(dòng)包位置 --> <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項(xiàng)目名 --> <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命令提示行 進(jìn)入到E盤generator目錄下 執(zhí)行
java -jar mybatis-generator-core-1.3.2.jar -configfile generator.xml -overwrite
這樣就表示創(chuàng)建成功
自動(dòng)幫我們創(chuàng)建了三個(gè)文件夾并把相應(yīng)的java文件創(chuàng)建好了
創(chuàng)建我們編寫sql語句的mapper.xml文件
創(chuàng)建對(duì)應(yīng)的實(shí)體類
創(chuàng)建對(duì)應(yīng)的dao接口
總結(jié)
以上所述是小編給大家介紹的Mybatis Generator自動(dòng)生成對(duì)應(yīng)的文件的實(shí)現(xiàn)方法,希望對(duì)大家有所幫助,如果大家有任何疑問請(qǐng)給我留言,小編會(huì)及時(shí)回復(fù)大家的。在此也非常感謝大家對(duì)創(chuàng)新互聯(lián)網(wǎng)站的支持!
本文名稱:MybatisGenerator自動(dòng)生成對(duì)應(yīng)文件的實(shí)現(xiàn)方法
文章網(wǎng)址:http://chinadenli.net/article32/jeippc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站內(nèi)鏈、網(wǎng)站設(shè)計(jì)、響應(yīng)式網(wǎng)站、品牌網(wǎng)站設(shè)計(jì)、商城網(wǎng)站、品牌網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)