日期:2014-05-20  浏览次数:20672 次

sqlMap中动态拼接sql语句问题?
如下Sql语句:
SELECT *
  FROM CUST_T A
 WHERE A.STATE = '00A'
  --循环开始  
  OR (A.CUST_ID = 123213 AND A.CUST_TYPE_ID IN (1,2,4))
  OR (A.CUST_ID = 243543 AND A.CUST_TYPE_ID IN (1,3,6,9))
  OR (A.CUST_ID = 343465 AND A.CUST_TYPE_ID IN (2,5))
  OR (A.CUST_ID = 123124 AND A.CUST_TYPE_ID IN (3,7,9))
  OR (A.CUST_ID = 143435 AND A.CUST_TYPE_ID IN (6))
  OR (A.CUST_ID = 565655 AND A.CUST_TYPE_ID IN (3,5))
  --循环结束
  AND A.CUST_LOCATION = '中国';

其中循环处的CUST_ID和CUST_TYPE_ID 参数是在程序中动态得出的,求助如何在ibatis的sqlMap中拼接上面的sql语句,求达人们帮助,谢谢。

------解决方案--------------------
好像有个<iterate>标签,你看看是否有吧
------解决方案--------------------
<sql id="kp_menu_fotonWhere">
<dynamic prepend="where">
<isNotEmpty prepend="and" property="menulabel">
menulabel=#menulabel#
</isNotEmpty>
<isGreaterThan prepend="and" property="displayorder"
compareValue="-1">
displayorder=#displayorder#
</isGreaterThan>
<isNotEmpty prepend="and" property="menuaction">
menuaction=#menuaction#
</isNotEmpty>
<isGreaterThan prepend="and" property="menuid"
compareValue="-1">
menuid=#menuid#
</isGreaterThan>
<isNotEmpty prepend="and" property="menuname">
menuname=#menuname#
</isNotEmpty>
<isGreaterThan prepend="and" property="parentid"
compareValue="-1">
parentid=#parentid#
</isGreaterThan>
<isNotEmpty prepend="and" property="oaimgpath">
oaimgpath=#oaimgpath#
</isNotEmpty>
<isNotEmpty prepend="and" property="isleaf">
isleaf=#isleaf#
</isNotEmpty>
</dynamic>
</sql>