ibatis 使用 in 查詢的幾種XML寫法

來源:互聯網
上載者:User

1.傳入參數是數組

<select id="Test"  resultClass="dto">             select *             from UserInfo             where userId in                 <iterate open="(" close=")" conjunction="," >                     #[]#                 </iterate>         </select> 
使用
 string[] arrays = new string[] { "1", "2", "3" };  Reader.QueryForList<?>("Ibatisnet.dao.<span style="font-family: Arial, Helvetica, sans-serif;">Test</span><span style="font-family: Arial, Helvetica, sans-serif;">", strValue ); </span>


2.使用上面的數組還可以使用對象中數組方式,寫法有點區別

<select id="Test"  resultClass="dto">             select *             from UserInfo             where userId in                 <iterate open="(" close=")" conjunction="," property="ArrValue" >                      #ArrValue[]#                 </iterate>         </select> 



3.  in 後面的資料,使用string傳入 ,但是記住如果是:請使用$ $,而不是# #

<select id="queryAllUserinfo" parameterClass="dto"resultClass="dto">SELECT u.USERID,ui.id,u.USERNAME,u.ACCOUNT,u.SEX,ui.specialty,ui.address,ui.idnumber,ui.school,ui.nation,ui.political_landscape,ui.phone,ui.email,ui.qq,ui.job_category,ui.stu_class,ui.create_tm,ui.modify_tmfrom eauser u,TB_USER_INFO ui         WHERE u.ACCOUNT = ui.ACCOUNT        <dynamic> <isNotEmpty prepend="AND" property="userids">                 ui.id in ($userids$)            </isNotEmpty></dynamic></select>



相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.