ibatis 使用 in 查询的几种XML写法

原文地址:http://blog.csdn.net/dracotianlong/article/details/35303593

这里摘抄学习

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", array);

2.使用上面的数组还可以使用对象中数组方式,写法有点区别

<select id="Test"  resultClass="dto"> 
            select * 
            from UserInfo 
            where userId in 
                <iterate open="(" close=")" conjunction="," property="ArrValue"&nbsp;> 
                    &nbsp;#ArrValue[]#&nbsp;
                </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_tm
        from eauser u,TB_USER_INFO ui 
        WHERE u.ACCOUNT = ui.ACCOUNT
        <dynamic>
             <isNotEmpty prepend="AND" property="userids">
                 ui.id in ($userids$)
            </isNotEmpty>
        </dynamic>
    </select>
 
原文地址:https://www.cnblogs.com/kevin-Y/p/4431794.html