freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

傳智播客springmvcmybatis由淺入深全套視頻教程v教案-資料下載頁

2025-04-16 22:49本頁面
  

【正文】 s Exception{ //獲取session SqlSession session = ()。 //獲限mapper接口實(shí)例 UserMapper userMapper = ()。 //如果使用占位符號則必須人為在傳參數(shù)中加% //ListUser list = (%管理員%)。 //如果使用${}原始符號則不用人為在參數(shù)中加% ListUser list = (管理員)。 //關(guān)閉session ()。 }使用session的selectList方法獲取pojo列表。 resultType總結(jié):輸出pojo對象和輸出pojo列表在sql中定義的resultType是一樣的。返回單個pojo對象要保證sql查詢出來的結(jié)果集為單條,mapper接口使用pojo對象作為方法返回值。返回pojo列表表示查詢出來的結(jié)果集可能為多條,mapper接口使用Listpojo對象作為方法返回值。 輸出hashmap輸出pojo對象可以改用hashmap輸出類型,將輸出的字段名稱作為map的key,value為字段值。 resultMap resultType可以指定pojo將查詢結(jié)果映射為pojo,但需要pojo的屬性名和sql查詢的列名一致方可映射成功。 如果sql查詢字段名和pojo的屬性名不一致,可以通過resultMap將字段名和屬性名作一個對應(yīng)關(guān)系 ,resultMap實(shí)質(zhì)上還需要將查詢結(jié)果映射到pojo對象中。 resultMap可以實(shí)現(xiàn)將查詢結(jié)果映射為復(fù)雜類型的pojo,比如在查詢結(jié)果映射對象中包括pojo和list實(shí)現(xiàn)一對一查詢和一對多查詢。 使用resultMap指定上邊定義的personmap。 定義resultMap,需要定義resultMap:id /:此屬性表示查詢結(jié)果集的唯一標(biāo)識,非常重要。如果是多個字段為復(fù)合唯一約束則定義多個id /。Property:表示person類的屬性。Column:表示sql查詢出來的字段名。Column和property放在一塊兒表示將sql查詢出來的字段映射到指定的pojo類屬性上。result /:普通結(jié)果,即pojo的屬性。 Mapper接口定義public ListUser findUserListResultMap() throws Exception。 動態(tài)sql(重點(diǎn))通過mybatis提供的各種標(biāo)簽方法實(shí)現(xiàn)動態(tài)拼接sql。 If! 傳遞pojo綜合查詢用戶信息 select id=findUserList parameterType=user resultType=user select * from user where 1=1 if test=id!=null and id!=39。39。 and id={id} /if if test=username!=null and username!=39。39。 and username like 39。%${username}%39。 /if /select注意要做不等于空字符串校驗(yàn)。 Where上邊的sql也可以改為:select id=findUserList parameterType=user resultType=user select * from user where if test=id!=null and id!=39。39。 and id={id} /if if test=username!=null and username!=39。39。 and username like 39。%${username}%39。 /if /where /selectwhere /可以自動處理第一個and。 foreach向sql傳遞數(shù)組或List,mybatis使用foreach解析,如下: 通過pojo傳遞listu 需求傳入多個id查詢用戶信息,用下邊兩個sql實(shí)現(xiàn):SELECT * FROM USERS WHERE username LIKE 39。%張%39。 AND (id =10 OR id =89 OR id=16)SELECT * FROM USERS WHERE username LIKE 39。%張%39。 id IN (10,89,16)u 在pojo中定義list屬性ids存儲多個用戶id,并添加getter/setter方法u if test=ids!=null and 0 foreach collection=ids open= and id in( close=) item=id separator=, {id} /foreach/ifu 測試代碼:ListInteger ids = new ArrayListInteger()。 (1)。//查詢id為1的用戶 (10)。 //查詢id為10的用戶 (ids)。 ListUser list = (queryVo)。 傳遞單個List,唯一不同的是只有一個List參數(shù)時它的參數(shù)名為list。如下:u select id=selectUserByList parameterType= resultType=user select * from user where ! 傳遞List,List中是pojo if test=list!=null foreach collection=list item=item open=and id in(separator=,close=) {} /foreach /if /where /selectu Mapper接口public ListUser selectUserByList(List userlist) throws Exception。u 測試:Public void testselectUserByList()throws Exception{ //獲取session SqlSession session = ()。 //獲限mapper接口實(shí)例 UserMapper userMapper = ()。 //構(gòu)造查詢條件List ListUser userlist = new ArrayListUser()。 User user = new User()。 (1)。 (user)。 user = new User()。 (2)。 (user)。 //傳遞userlist列表查詢用戶列表 ListUserlist = (userlist)。 //關(guān)閉session ()。 } 傳遞單個數(shù)組(數(shù)組中是pojo):請閱讀文檔學(xué)習(xí)。u ! 傳遞數(shù)組綜合查詢用戶信息 select id=selectUserByArray parameterType=Object[] resultType=user select * from user where ! 傳遞數(shù)組 if test=array!=null foreach collection=array index=index item=item open=and id in(separator=,close=) {} /foreach /if /where /selectsql只接收一個數(shù)組參數(shù),這時sql解析參數(shù)的名稱mybatis固定為array,如果數(shù)組是通過一個pojo傳遞到sql則參數(shù)的名稱為pojo中的屬性名。index:為數(shù)組的下標(biāo)。item:為數(shù)組每個元素的名稱,名稱隨意定義open:循環(huán)開始close:循環(huán)結(jié)束separator:中間分隔輸出u Mapper接口:public ListUser selectUserByArray(Object[] userlist) throws Exception。u 測試:Public void testselectUserByArray()throws Exception{ //獲取session SqlSession session = ()。 //獲限mapper接口實(shí)例 UserMapper userMapper = ()。 //構(gòu)造查詢條件List Object[] userlist = new Object[2]。 User user = new User()。 (1)。 userlist[0]=user。 user = new User()。 (2)。 userlist[1]=user。 //傳遞user對象查詢用戶列表 ListUserlist = (userlist)。 //關(guān)閉session ()。 } 傳遞單個數(shù)組(數(shù)組中是字符串類型):請閱讀文檔學(xué)習(xí)。u ! 傳遞數(shù)組綜合查詢用戶信息 select id=selectUserByArray parameterType=Object[] resultType=user select * from user where ! 傳遞數(shù)組 if test=array!=null foreach collection=arrayindex=indexitem=itemopen=and id in(separator=,close=) {item} /foreach /if /where /select如果數(shù)組中是簡單類型則寫為{item},不用再通過ognl獲取對象屬性值了。u Mapper接口:public ListUser selectUserByArray(Object[] userlist) throws Exception。u 測試:Public void testselectUserByArray()throws Exception{ //獲取session SqlSession session = ()。 //獲限mapper接口實(shí)例 UserMapper userMapper = ()。 //構(gòu)造查詢條件List Object[] userlist = new Object[2]。 userlist[0]=”1”。 userlist[1]=”2”。 //傳遞user對象查詢用戶列表 ListUserlist = (userlist)。 //關(guān)閉session ()。 } Sql片段Sql中可將重復(fù)的sql提取出來,使用時用include引用即可,最終達(dá)到sql重用的目的,如下:! 傳遞pojo綜合查詢用戶信息 select id=findUserList parameterType=user resultType=user select * from user where if test=id!=null and id!=39。39。 and id={id} /if if test=username!=null and username!=39。39。 and username like 39。%${username}%39。 /if /where /selectu 將where條件抽取出來:sql id=query_user_where if test=id!=null and id!=39。39。 and id={id} /if if test=username!=null and username!=39。39。 and username like 39。%${username}%39。 /if/sqlu 使用include引用:select id=findUserList parameterType=user resultType=user select * from user where include refid=query_user_where/ /where /select注意:,則在引用時需要加上namespace,如下:include refid=”/5 關(guān)聯(lián)查詢 商品訂單數(shù)據(jù)模型用戶表:user記錄了購買商品的用戶信息Id:唯一標(biāo)識一個用戶訂單表:orders記錄了用戶創(chuàng)建的訂單創(chuàng)建用戶:user_id(外鍵)訂單號創(chuàng)建時間訂單狀態(tài) 外鍵:user_id
點(diǎn)擊復(fù)制文檔內(nèi)容
教學(xué)教案相關(guān)推薦
文庫吧 www.dybbs8.com
備案圖鄂ICP備17016276號-1