新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
使用MyBatis怎么實現(xiàn)動態(tài)查詢和模糊查詢功能-創(chuàng)新互聯(lián)
使用MyBatis怎么實現(xiàn)動態(tài)查詢和模糊查詢功能?相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
要實現(xiàn)查詢,咱們就先有個數(shù)據(jù)庫,截圖如下,其中cityAreaId是外鍵,本次可以忽略;
下面Branches是我的實體類,里面有name和address屬性;
接口中方法:
public ListfinDongTai(@Param("name")String name,@Param("add")String address);//動態(tài) public List findLike(@Param("name")String name,@Param("add")String address);//模糊
MyBatis的接口映射文件的代碼:
動態(tài)查詢:
模糊查詢:
然后就是main方法實現(xiàn)了:
Listlist=new BranchesImpl().finDongTai("建設銀行", ""); for (Branches branches : list) { System.out.println("名稱:"+branches.getName()+"\t---\t地址:"+branches.getAddress()); } List list=new BranchesImpl().findLike("支行", "路"); for (Branches branches : list) { System.out.println("名稱:"+branches.getName()+"\t---\t地址:"+branches.getAddress()); }
看完上述內(nèi)容,你們掌握使用MyBatis怎么實現(xiàn)動態(tài)查詢和模糊查詢功能的方法了嗎?如果還想學到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!
名稱欄目:使用MyBatis怎么實現(xiàn)動態(tài)查詢和模糊查詢功能-創(chuàng)新互聯(lián)
網(wǎng)站地址:http://fisionsoft.com.cn/article/dpicgs.html