A list/map can be passed as a parameterClass to an iBATIS sql map to iterate. A IN clause is the basic example of iteration over a list and create comma separated query. For example, if a list have 3 elements (10,20,30). It is passed as parameterClass in the query for a IN clause, the syntax is like following:
<select id="getAllScore" resultClass="score" parameterClass="java.util.List">
SELECT * FROM score WHERE id IN
<iterate open="(" close=")" conjunction=",">
#value[]#
</iterate>
</select>
You can define a list in the parameterClass. But what about a array? You cannot define array like int[] in the parameter class. Most surprising thing is, for an array you do not have to define a parameterClass in iBATIS. If nothing is defined as parameterClass then it is considered as Array.
If you want to iterate over an array with then the following code works fine. Every array elements will be printed in the code #[]#.
<select id="getAllScore" resultClass="score">
SELECT * FROM score WHERE id IN
<iterate open="(" close=")" conjunction=",">
#[]#
</iterate>
</select>
By: Md. Shahjalal

