![Mybatis generator生成工具簡(jiǎn)單介紹_第1頁(yè)](http://file3.renrendoc.com/fileroot_temp3/2022-1/1/8834839d-6a96-4720-ae06-1cd9510da15c/8834839d-6a96-4720-ae06-1cd9510da15c1.gif)
下載本文檔
版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、mybatis generator生成工具簡(jiǎn)單介紹mybatis generator生成工具容易介紹mybatis generator 其主要的功能就是便利,快捷的創(chuàng)建好dao,entry,xml 加快了開發(fā)速度,用法方面按照其提供的規(guī)章配置好就ok這里還有一個(gè)重要的開發(fā)場(chǎng)景,開發(fā)過(guò)程中,對(duì)數(shù)據(jù)庫(kù)的操作絕對(duì)無(wú)數(shù),比如新增字段什么的,你只要將原先自動(dòng)生成的一套代碼刪除,重新再生成一份,這就完善解決了,但是這樣做的前提是,你必需對(duì)生成后的代碼不改動(dòng),只是用法。不需要想手動(dòng)開發(fā)寫代碼那樣處處改代碼,還不安改漏地方。其實(shí)這個(gè)的實(shí)現(xiàn)方式也是五光十色的,寫一種比較頻繁的主要流程第一步:添加依靠主要是jdb
2、c和generator org.mybatis.generator mybatis-generator-core 1.3.6 mysql mysql-connector-java 5.1.38 其次步:配置 generatorconfig.xml這個(gè)文件主要是對(duì) 從哪來(lái),到哪去的描述,還有一些特別要求的配置 第三步:主要看你個(gè)人的需求,對(duì)注釋,分頁(yè)啥的有啥要求不,可以重寫幾個(gè)辦法對(duì)其舉行改造主要舉幾個(gè)例子對(duì)注釋的修改 newbatisgeneratorpublic class newbatisgenerator extends defaultcommentgenerator private p
3、roperties properties; private properties systempro; private boolean suppressdate; private boolean suppressallcomments; private string currentdatestr; public newbatisgenerator() super(); properties = new properties(); systempro = system.getproperties(); suppressdate = false; suppressallcomments = fal
4、se; currentdatestr = (new simpledateformat("yyyy-mm-dd").format(new date(); /* * 對(duì)類的注解 * param toplevelclass * param introspectedtable */ override public void addmodelclasscomment(toplevelclass toplevelclass, introspectedtable introspectedtable) toplevelclass.addjavadocline(&qu
5、ot;/*"); toplevelclass.addjavadocline(" * 這是mybatis generator自動(dòng)生成的model class."); stringbuilder sb = new stringbuilder(); sb.append(" * 對(duì)應(yīng)的數(shù)據(jù)表是 : "); sb.append(introspectedtable.getfullyqualifiedtable(); toplevelclass.addjavadocline(sb.tostring(); string
6、tableremarks = introspectedtable.getremarks(); if (!stringutils.isempty(tableremarks) sb.setlength(0); sb.append(" * 數(shù)據(jù)表注釋 : "); sb.append(tableremarks); toplevelclass.addjavadocline(sb.tostring(); sb.setlength(0); sb.append(" * author "); sb.append(systempro.getp
7、roperty(""); toplevelclass.addjavadocline(sb.tostring(); string curdatestring = (new simpledateformat("yyyy-mm-dd hh:mm:ss").format(new date(); sb.setlength(0); sb.append(" * date "); sb.append(curdatestring); toplevelclass.addjavadoclin
8、e(sb.tostring(); toplevelclass.addjavadocline(" */"); /* * 生成的實(shí)體增強(qiáng)字段的中文注釋 */ public void addfieldcomment(field field, introspectedtable introspectedtable, introspectedcolumn introspectedcolumn) if (suppressallcomments) return; stringbuilder sb = new stringbuilder(); field.addjavado
9、cline("/*"); sb.append(" * "); sb.append(introspectedcolumn.getremarks(); field.addjavadocline(sb.tostring().replace("n", " "); field.addjavadocline(" */"); 對(duì)分頁(yè)的添加 mysqlpaginationplugin 自動(dòng)生成帶分頁(yè)插件public class my
10、sqlpaginationplugin extends pluginadapter public mysqlpaginationplugin() public boolean modelexampleclassgenerated(toplevelclass toplevelclass, introspectedtable introspectedtable) this.addlimit(toplevelclass, introspectedtable, "limitstart"); this.addlimit(toplevelclass, introspec
11、tedtable, "limitsize"); return super.modelexampleclassgenerated(toplevelclass, introspectedtable); public boolean sqlmapselectbyexamplewithoutblobselementgenerated(xmlelement element, introspectedtable introspectedtable) xmlelement isnotnullelement = new xmlelement("if&
12、;quot;); isnotnullelement .addattribute(new attribute("test", "limitstart != null and limitsize >= 0"); isnotnullelement.addelement(new textelement("limit limitstart , limitsize"); element.addelement(isnotnullelement); return super.sqlmapselec
13、tbyexamplewithoutblobselementgenerated(element, introspectedtable); public boolean sqlmapselectbyexamplewithblobselementgenerated(xmlelement element, introspectedtable introspectedtable) xmlelement isnotnullelement = new xmlelement("if"); isnotnullelement .addattribute(new attribut
14、e("test", "limitstart != null and limitsize >= 0"); isnotnullelement.addelement(new textelement("limit limitstart , limitsize"); element.addelement(isnotnullelement); return super.sqlmapselectbyexamplewithblobselementgenerated(element, introsp
15、ectedtable); private void addlimit(toplevelclass toplevelclass, introspectedtable introspectedtable, string name) commentgenerator commentgenerator = this.context.getcommentgenerator(); field field = new field(); field.setvisibility(javavisibility.protected); field.settype(primitivetypewrapper.getin
16、tegerinstance(); field.setname(name); commentgenerator.addfieldcomment(field, introspectedtable); toplevelclass.addfield(field); char c = name.charat(0); string camel = character.touppercase(c) + name.substring(1); method method = new method(); method.setvisibility(javavisibility.public); method.set
17、name("set" + camel); method.addparameter(new parameter(primitivetypewrapper.getintegerinstance(), name); stringbuilder sb = new stringbuilder(); sb.append("this."); sb.append(name); sb.append(" = "); sb.append(name); sb.append(""
18、;); method.addbodyline(sb.tostring(); commentgenerator.addgeneralmethodcomment(method, introspectedtable); toplevelclass.addmethod(method); method gettermethod = abstractjavagenerator.getgetter(field); commentgenerator.addgeneralmethodcomment(gettermethod, introspectedtable); toplevelclass.addmethod(gettermethod); public boolean validate(list warnings) return true; /* * 生成mapper.xml,文件內(nèi)容會(huì)被清空再寫入 * */ override public boolean sqlmapgenerated(generatedxmlfile sqlmap, introspectedtable introspectedtable) sql
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 一年級(jí)夜色聽評(píng)課記錄
- 湘教版地理八年級(jí)下冊(cè)5.3《西北地區(qū)和青藏地區(qū)》(第2課時(shí))聽課評(píng)課記錄
- 魯教版數(shù)學(xué)八年級(jí)下冊(cè)8.3《用公式法解一元二次方程》聽評(píng)課記錄
- 五年級(jí)數(shù)學(xué)口算競(jìng)賽題
- 蘇教版小學(xué)數(shù)學(xué)三年級(jí)下冊(cè)口算題
- 蘇教版二年級(jí)下冊(cè)數(shù)學(xué)口算練習(xí)題費(fèi)
- 小學(xué)數(shù)學(xué)-六年級(jí)下冊(cè)-4-3 正比例圖像 聽評(píng)課記錄
- 船員勞動(dòng)合同范本
- 商業(yè)房屋租借合同范本
- 2025年度高級(jí)技術(shù)人才聘用與管理制度合同
- DB33-T 2082-2017(2021)托幼機(jī)構(gòu)消毒衛(wèi)生規(guī)范
- 提高攜帶雙J管患者的健康教育落實(shí)率泌尿科品管圈課件
- 《隋朝的統(tǒng)一與滅亡》 -完整版課件
- API-650-1鋼制焊接石油儲(chǔ)罐
- 職業(yè)危害告知書(最新版)
- 金融科技課件(完整版)
- 醫(yī)院壓力性損傷患者質(zhì)控標(biāo)準(zhǔn)
- 醫(yī)療機(jī)構(gòu)規(guī)章制度診所診所規(guī)章制度
- 飲品店操作流程圖
- 風(fēng)居住的街道鋼琴二胡合奏譜
- PADS元件封裝制作規(guī)范要點(diǎn)
評(píng)論
0/150
提交評(píng)論