ibatis批量操作 這文章的補(bǔ)充吧。
review代碼的時(shí)候發(fā)現(xiàn)一個(gè)頁(yè)面應(yīng)用排序設(shè)置功能,原先代碼中,進(jìn)行了循環(huán)update實(shí)現(xiàn)。雖然應(yīng)用較少,不過(guò)無(wú)謂浪費(fèi)數(shù)據(jù)庫(kù)鏈接實(shí)在不是一個(gè)好的想法。
所以,我覺(jué)得應(yīng)該杜絕循環(huán)中的任何數(shù)據(jù)可操作才能避免很多地雷的埋下。
修改后:
批量更新語(yǔ)句的寫法,基于ibatis,只使用iterate 標(biāo)簽:
<update id="batchUpdateShoWorder" parameterClass="map"> update wi_open_app_sub_new set gmtModified=NOW() , showOrder = <iterate實(shí)現(xiàn)sql語(yǔ)句:
update wi_open_app_sub_new set showOrder = case when appid =10199 then 1 when appid =4 then 2 when appid =3 then 3 when appid =10134 then 4 when appid=1 then 5 when appid=5 then 6 end wheremerchantid='8a22b1864b498152014b498246610001' and appid in( 10199, 4, 3 , 10134, 1, 5 );
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注