iBatis之Iterator的使用

2022-03-17 20:02:56 字數 1641 閱讀 1519

一:前言

現在這個專案使用的是ibatis,我剛剛開始的時候說是用mybatis,因為我以前用過,覺得還是比較好用的啊,而且不像ibatis樣,查什麼乙個字段不能多也不能少,覺得好無語啊。

二:內容

自己現在接觸的iterator有如下兩種用處

(一):批量迴圈插入

批量插入的話有可以分開說,一種是在後台**中,批量插入,一種是在資料庫中迴圈插入

(1):在先說後台批量插入的,直接上**

return (integer)this.getsqlmapclienttemplate().execute(new

sqlmapclientcallback()

count=executor.executebatch();

return

count;

}});

insert into user(id,,user_id,user_name,start_time,end_time,) values (#id#,#userid#,#username#,#starttime#,#endtime#)

(2):在sql中進行迴圈插入

insert 

into user(id,user_id,user_name.start_time,end_time)

values(#list.id#,#list.useid#,#list.username#,#list.starttime#,#list.endtime#)

(二):在sql中我們會使用到in這種查詢,in裡面一般就如(1,2,3,...)這種形式所以我們可以用iterator來迴圈生成這種形式

resultmap="getuser">

[cdata[

select * from user o where o.user_role=2]]>

o.user_id in

property="list">#list#

這裡必須加上property="pileslist",否則會報下面的錯誤

---cause: com.ibatis.sqlmap.client.sqlmapexception: parameterobject

or property was not a collection, array or iterator.

二是使用list當作引數

[cdata[

select * from user o where o.user_role=2]]>and o.pile_id in

#list#

這裡面就不用加property="list"這個屬性,這裡還有一點要注意的就是不能加成這樣的

[cdata[

select * from user o where o.user_role=2]]>

and o.pile_id in

#list#

如果加了這個判斷也是會報錯的,這點使得我很與鬱悶啊,這個isnotempty判斷不了list是否為空的,list的空值是寫的,所以只能用if判斷。

三:總結

今天知道了旁邊的同事要走,其實挺無語的。不知道怎麼的,我的感觸還是很深的,每個人都有自己的路去選擇,盡量保持平常的心態吧。我的心很大,所以我要堅定下去。努力加油。都衝吧。

ibatis實戰之OR對映

相對hibernate等orm實現而言,ibatis的對映配置更為簡潔直接,以下是乙個典型的配置檔案。insert into user values id name age update user set name name where id id 能夠看到,對映檔案主要分為兩個部分 模組配置和st...

php spl之迭代器iterator

常用方法 ksort 根據鍵進行排序 asort 根據值進行排序 seek 將interator裡的第乙個元素從0開始標記,依次遞增,seek是指跳到指定標記 迴圈時的方法包括current,rewind,key,next,valid.使用方式 常用的有foreach和while,其中我們以前所使用...

java之Iterator迭代器

2016年8月28日 每週一篇部落格 第三週 本週沒有學到什麼,哀哉 listoptions new arraylist iteratoriterator options.iterator while iterator.hasnext iterator.next 指標 每調一次就會建立乙個物件,所以...