I have a personal website which uses iBATIS 2.3.x. Recently I’m adding a complex searching feature to the site, need to query the data by a list of object, likes:
public Class PromotionAttribute {
String attributeName;
String attributeValue;
}
The query looks like:
select p.* from promotions p
join promotion_attributes pa on p.id=pa.id
where
<foreach item="PromotionAttribute" index="index" collection="list" open="(" separator=" or " close=")">
pa.attribute_name=#{attributeName} and pa.attribute_value=#{attributeValue}#
</foreach>
For the above query, it’s only a pseudocode since I didn’t use the higher version of iBATIS, its meaning is I want to generate a dynamic query condition.
My question is:
I’m not sure whether iBATIS 2.3.x supports “foreach” tag, if not, how to implement this kind of query?
Thanks,
Shuiqing
You can use “iterate” in 2.3.* in place of foreach like below. Only iBATIS 3/ MyBATIS uses OGNL based expressions like choose, foreach, trim…
You can use parameterClass as “java.util.Map” and pass list value by setting “productTypes” as key.