This is a feature available in iBatis but it is not mentioned in the documentation. You can find the example in the iBatis source code under the unit tests.
Let’s said I need to run the following SQL statement
select * from my_table where col_1 in ('1','2','3')
So how do I pass in the values of 1, 2 and 3 ?
In this case you need to pass in a list parameter. The correct iBatis syntax should be
< id="select-test" resultmap="MyTableResult" parameterclass="list">
select * from my_table where col_1 in
< open="(" close=")" conjunction=",">
#[]#
< /iterate >
< /select >
And in Java you should pass in a java.util.List. E.g.
Listlist = new ArrayList (3);
list.add("1");
list.add("2");
list.add("3");
List objs = sqlMapClient.queryForList("select-test",list);
This is another example
< id="getProducts" parameterclass="Product" resultclass="Product">
SELECT * FROM Products
< prepend="WHERE productType IN ">
< property="productTypes" open="(" close=")" conjunction=",">
productType=#productType#
< /iterate>
< /dynamic>
0 comments:
Post a Comment