Saturday, 9 March 2013

Parameter jenis java.util.List dalam iBatis 2 SQL Map

Contoh hantar list sebagai parameter dalam sqlmapping iBatis
Contoh ni hantar list dalam 1 parameter map jenis java.util.Map dengan var "p_dept_code_list"
....
 <select id="ims_getSummary" parameterClass="java.util.Map" resultMap="ims_summary_resultMap">  
 select   
  SSL_ANALYSIS_ID, SSL_STAFF_ID, SSL_QUALIFICATION_LEVEL, SSL_UNIVERSITY_NAME, SSL_STUDY_MODE, SSL_DATE_FROM, SSL_DATE_TO,  
  COUNT(SLE_EXTENSION_TYPE) TOTAL_EXTENSION,  
  sm_staff_name staff_name, sm_dept_code dept_code  
 from SSL, SM, SLE  
 where SM_STAFF_ID = SSL_STAFF_ID  
 and SSL_STAFF_ID = SLE_STAFF_ID  
 and SSL_QUALIFICATION_LEVEL = SLE_QUALIFICATION_LEVEL  
 <iterate prepend="AND" open="(" close=")" property="p_dept_code_list" conjunction="OR" >  
 SM_DEPT_CODE=#p_dept_code_list[]#  
 </iterate>  
 group by SSL_ANALYSIS_ID, SSL_STAFF_ID, SSL_QUALIFICATION_LEVEL, SSL_UNIVERSITY_NAME, SSL_STUDY_MODE, SSL_DATE_FROM, SSL_DATE_TO,   
 SM_STAFF_NAME, sm_dept_code  
 order by sm_staff_name, ssl_qualification_level  
 </select>  
....
sql yang dijana mungkin AND ( SM_DEPT_CODE = 'val1' OR SM_DEPT_CODE = 'val2' ....... )

1 comment:

Aidy Azizi Syahmi Ahmad Said said...

Ok, parameter list boleh hantar, tapi jika list tu kosong, condition tidak included, sebabkan sql dalam iteration x filter list.