项目用的是ibatis-2.3.4.726,不是mybatis。
一、我的应用
1.TCommission.xml (用iterate合成 in语句)
<select id="queryMap" parameterClass="com.hanpeng.base.phone.model.TCommission" resultClass="java.util.HashMap"> <include refid="paginationStart"/> SELECT T1.PRODUCT_NUM as productNum , T1.TYPE_NUM as typeNum , T1.FAST_COMMISSION as fastCommission , T1.NORM_COMMISSION as normCommission , T1.CREATE_DATE as createDate , T1.EMPLOYEE_ID as employeeId , T1.ALTER_DATE as alterDate , T1.OTHER_FAST_COMMISSION as otherFastCommission , T1.OTHER_NORM_COMMISSION as otherNormCommission , T1.MONEY as money , T1.FAST_PRICE as fastPrice , T1.NORM_PRICE as normPrice , T1.ALL_FAST_COMMISSION as allFastCommission , T1.ALL_NORM_COMMISSION as allNormCommission , T1.OTHER_FAST_PRICE as otherFastPrice , T1.OTHER_NORM_PRICE as otherNormPrice , T1.ALL_FAST_PRICE as allFastPrice , T1.ALL_NORM_PRICE as allNormPrice, T2.PRODUCT_NAME as productName, T3.TYPE_NAME as typeName, T2.Area_Code as areaCode FROM T_COMMISSION T1 LEFT JOIN T_PRODUCT_TYPE T2 ON T1.PRODUCT_NUM=T2.PRODUCT_NUM LEFT JOIN T_COMMISSION_TYPE T3 ON T1.TYPE_NUM=T3.TYPE_NUM <dynamic prepend="WHERE"> <isNotEmpty prepend=" AND " property="productNum"> T1.PRODUCT_NUM = #productNum# </isNotEmpty> <isNotEmpty prepend=" AND " property="typeNum"> T1.TYPE_NUM = #typeNum# </isNotEmpty> <isNotEmpty prepend=" AND " property="fastCommission"> T1.FAST_COMMISSION = #fastCommission# </isNotEmpty> <isNotEmpty prepend=" AND " property="normCommission"> T1.NORM_COMMISSION = #normCommission# </isNotEmpty> <isNotEmpty prepend=" AND " property="createDate"> T1.CREATE_DATE = #createDate# </isNotEmpty> <isNotEmpty prepend=" AND " property="employeeId"> T1.EMPLOYEE_ID = #employeeId# </isNotEmpty> <isNotEmpty prepend=" AND " property="alterDate"> T1.ALTER_DATE = #alterDate# </isNotEmpty> <isNotEmpty prepend=" AND " property="otherFastCommission"> T1.OTHER_FAST_COMMISSION = #otherFastCommission# </isNotEmpty> <isNotEmpty prepend=" AND " property="otherNormCommission"> T1.OTHER_NORM_COMMISSION = #otherNormCommission# </isNotEmpty> <isNotEmpty prepend=" AND " property="money"> T1.MONEY = #money# </isNotEmpty> <isNotEmpty prepend=" AND " property="fastPrice"> T1.FAST_PRICE = #fastPrice# </isNotEmpty> <isNotEmpty prepend=" AND " property="normPrice"> T1.NORM_PRICE = #normPrice# </isNotEmpty> <isNotEmpty prepend=" AND " property="allFastCommission"> T1.ALL_FAST_COMMISSION = #allFastCommission# </isNotEmpty> <isNotEmpty prepend=" AND " property="allNormCommission"> T1.ALL_NORM_COMMISSION = #allNormCommission# </isNotEmpty> <isNotEmpty prepend=" AND " property="otherFastPrice"> T1.OTHER_FAST_PRICE = #otherFastPrice# </isNotEmpty> <isNotEmpty prepend=" AND " property="otherNormPrice"> T1.OTHER_NORM_PRICE = #otherNormPrice# </isNotEmpty> <isNotEmpty prepend=" AND " property="allFastPrice"> T1.ALL_FAST_PRICE = #allFastPrice# </isNotEmpty> <isNotEmpty prepend=" AND " property="allNormPrice"> T1.ALL_NORM_PRICE = #allNormPrice# </isNotEmpty> <isNotEmpty prepend=" AND " property="areaCode"> T2.AREA_CODE = #areaCode# </isNotEmpty> <isNotEmpty prepend=" AND " property="provinceCode"> T2.PROVINCE_CODE = #provinceCode# </isNotEmpty> <isNotEmpty prepend=" AND " property="operatorsCode"> T2.OPERATORS_CODE = #operatorsCode# </isNotEmpty> <isNotEmpty prepend=" AND " property="myMoneys"> T1.MONEY IN <iterate property="myMoneys" open="(" close=")" conjunction=","> #myMoneys[]# </iterate> </isNotEmpty> </dynamic> <include refid="paginationEnd"/> </select>
2.TCommission.java (model实体,定义Double数组myMoneys)
public class TCommission extends BaseModel{ // : PRODUCT_NUM private String productNum; // : TYPE_NUM private String typeNum; // : FAST_COMMISSION private java.lang.Double fastCommission; // : NORM_COMMISSION // : FAST_PRICE private java.lang.Double fastPrice; private String productName;//产品名称 private String typeName;//策略名称 private String areaCode;//区号 private String provinceCode;//省号 private String operatorsCode;//运营商 private Double[] myMoneys;//面值数组
二、转载lwy内容
1.
<iterate property="states" open="(" close=")" conjunction="OR"> <isNotEqual compareValue="1" property="states[]"> STATE=#states[]# </isNotEqual> <isEqual compareValue="1" property="states[]"> STATE not in('0','-1') </isEqual> </iterate>
取循环中的值property与给定值compareValue 作比较 动态拼劲sql,
此例中states为String[],若states为List<?> 可用states[].xxx取值。
iterate标签还有个compareProperty属性,猜测为与某字段对比(未测试)。
2.
<isNotEmpty prepend=" AND " property="operators"> OPERATORS_CODE in <iterate property="operators" open="(" close=")" conjunction=","> #operators[]# </iterate> </isNotEmpty>