這篇文章主要講解了Mybatis逆向工程的實現(xiàn),內(nèi)容清晰明了,對此有興趣的小伙伴可以學(xué)習(xí)一下,相信大家閱讀完之后會有幫助。
簡單的理解,MyBatis逆向工程,就是通過相應(yīng)插件,自動生成MyBatis數(shù)據(jù)庫連接的一些文件。
mybatis需要編寫sql語句,mybatis官方提供逆向工程,可以針對單表自動生成mybatis執(zhí)行所需要的代碼(mapper.java、mapper.xml、pojo…),提高工作效率。
命令:
mvn mybatis-generator:generate
項目結(jié)構(gòu):
generatorConfig.xml內(nèi)容示例
<?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> <context id="mysqlgenerator" targetRuntime="MyBatis3"> <property name="autoDelimitKeywords" value="true"/> <!--可以使用``包括字段名,避免字段名與sql保留字沖突報錯--> <property name="beginningDelimiter" value="`"/> <property name="endingDelimiter" value="`"/> <!-- 自動生成toString方法 --> <plugin type="org.mybatis.generator.plugins.ToStringPlugin"/> <!-- 自動生成equals方法和hashcode方法 --> <plugin type="org.mybatis.generator.plugins.EqualsHashCodePlugin"/> <!-- 非官方插件 https://github.com/itfsw/mybatis-generator-plugin --> <!-- 查詢單條數(shù)據(jù)插件 --> <plugin type="com.itfsw.mybatis.generator.plugins.SelectOneByExamplePlugin"/> <!-- 查詢結(jié)果選擇性返回插件 --> <plugin type="com.itfsw.mybatis.generator.plugins.SelectSelectivePlugin"/> <!-- Example Criteria 增強插件 --> <plugin type="com.itfsw.mybatis.generator.plugins.ExampleEnhancedPlugin"/> <!-- 數(shù)據(jù)Model屬性對應(yīng)Column獲取插件 --> <plugin type="com.itfsw.mybatis.generator.plugins.ModelColumnPlugin"/> <!-- 邏輯刪除插件 --> <plugin type="com.itfsw.mybatis.generator.plugins.LogicalDeletePlugin"> <!-- 這里配置的是全局邏輯刪除列和邏輯刪除值,當然在table中配置的值會覆蓋該全局配置 --> <!-- 邏輯刪除列類型只能為數(shù)字、字符串或者布爾類型,數(shù)據(jù)庫中用tinyint(1) --> <property name="logicalDeleteColumn" value="deleted"/> <!-- 邏輯刪除-已刪除值 --> <property name="logicalDeleteValue" value="1"/> <!-- 邏輯刪除-未刪除值 --> <property name="logicalUnDeleteValue" value="0"/> </plugin> <commentGenerator> <property name="suppressDate" value="true"/> <!--<property name="suppressAllComments" value="true"/>--> </commentGenerator> <!--數(shù)據(jù)庫連接信息--> <jdbcConnection driverClass="com.mysql.jdbc.Driver" connectionURL="jdbc:mysql://192.168.1.100:3306/theorydance?useUnicode=true&characterEncoding=UTF-8&serverTimezone=UTC&verifyServerCertificate=false&useSSL=false" userId="root" password="123456"/> <javaTypeResolver> <property name="useJSR310Types" value="true"/> </javaTypeResolver> <javaModelGenerator targetPackage="demo.theorydance.db.domain" targetProject="src/main/java"/> <sqlMapGenerator targetPackage="demo.theorydance.db.dao" targetProject="src/main/resources"/> <javaClientGenerator type="XMLMAPPER" targetPackage="demo.theorydance.db.dao" targetProject="src/main/java"/> <!--表名--> <table tableName="student"></table> </context> </generatorConfiguration>
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)建站www.rwnh.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
分享題目:Mybatis逆向工程的實現(xiàn)-創(chuàng)新互聯(lián)
網(wǎng)站URL:http://www.rwnh.cn/article42/dcoghc.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供微信公眾號、定制開發(fā)、網(wǎng)站營銷、網(wǎng)站導(dǎo)航、App設(shè)計、軟件開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容