SELECT * FROM DW_KHFXTB WHERE COL1>=”+strJEQ+” AND COL1<=”+strJEH+” AND CS>=”+strCSQ+” AND CS<=”+strCSH+” AND EXISTS (SELECT * FROM DW_YJCKTB WHERE SITENO IN(“+result+”) AND DW_YJCKTB.CLIENTNO = DW_KHFXTB.CLIENTNO) AND KIND=”””+strSJLX+””” ORDER BY COL1 DESC FETCH FIRST “+strJLS+” ROWS ONLY 如上sql语句在xml文件中该怎么写 尤其是in() 括号里面该怎么写 |
|
55分 |
看可不可以这样,in后面再加一个select,或者传过来一个字符串。用逗号隔开
|
传入list或者一个collection的参数
<dynamic prepend="where"> <isNotEmpty prepend="and" property="result"> <![CDATA[ SITENO in ]]> <iterate property="result" conjunction="," open="(" close=")"> #result[]# </iterate> </isNotEmpty> </dynamic> |
|
….. |
|
sql 中 数字类型的直接传in(1,2,3)字符串型的传in(””1″”,””2″”,””3″”)ibatis写法 $参数$
|
|
List list ={1,2,3}
String s=””; for(int i=0;i<list.size();i++){ s+=”,”””+list.get(i)+””””; } s=s.subtring(1); 结果是s=””1″”,””2″”,””3″” |
|
s.substring(1)
|
|
使用$参数名$就可以了,$符号会原样输出参数如select * form userInfo where id in ($ids$) ids=”1,32,25″ 即为select * from userInfo where id in (1,32,25) 如果id为字符串类型,你在组装ids字符串时对应加上单引号为ids=”””1″”,””32″”,””25″””;
|