2018-08-01 14:20:13 1122瀏覽
今天扣丁學(xué)堂Java培訓(xùn)老師給大家介紹一下關(guān)于Java持久層MyBatis實(shí)現(xiàn)動(dòng)態(tài)查詢、模糊查詢功能的詳細(xì)介紹,下面我們一起來看一下吧。首先我們要實(shí)現(xiàn)數(shù)據(jù)查詢,就必須要有個(gè)數(shù)據(jù)庫,截圖如下,其中cityAreaId是外鍵,本次可以忽略;
public List<Branches> finDongTai(@Param("name")String name,@Param("add")String address);//動(dòng)態(tài) public List<Branches> findLike(@Param("name")String name,@Param("add")String address);//模糊
<select id="finDongTai" resultType="com.wj.entity.Branches" > SELECT * FROM Branches where 1=1 <if test="name!=''and name!=null"> and name =#{name} </if> <if test="add!=''and add!=null"> and address =#{add} </if> </select>
<select id="findLike" resultType="com.wj.entity.Branches" > SELECT * FROM Branches where name like "%"#{name}"%" and address like "%"#{add}"%" </select>
List<Branches> list=new BranchesImpl().finDongTai("建設(shè)銀行", ""); for (Branches branches : list) { System.out.println("名稱:"+branches.getName()+"\t---\t地址:"+branches.getAddress()); } List<Branches> list=new BranchesImpl().findLike("支行", "路"); for (Branches branches : list) { System.out.println("名稱:"+branches.getName()+"\t---\t地址:"+branches.getAddress()); }
動(dòng)態(tài)查詢結(jié)果:
模糊查詢結(jié)果:
以上所述是小編給大家介紹的MyBatis實(shí)現(xiàn)動(dòng)態(tài)查詢、模糊查詢功能,希望對(duì)大家有所幫助,非常感謝大家對(duì)扣丁學(xué)堂的支持,最后想要了解更多內(nèi)容的小伙伴可以登錄扣丁學(xué)堂官網(wǎng)咨詢??鄱W(xué)堂不僅有專業(yè)的老師和與時(shí)俱進(jìn)的課程體系,還有大量的Java視頻教程供學(xué)員觀看學(xué)習(xí),想要快速學(xué)習(xí)Java開發(fā)技術(shù)的小伙伴快快行動(dòng)吧。
【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】
查看更多關(guān)于“Java開發(fā)資訊”的相關(guān)文章>>