i am using Ibatis 2 and i am asking how to print array of objects (as the official docs are gone). This is the example data similar to the one i have:
[
{
"firstStr": "D392",
"secondStr": "N3895"
},
{
"firstStr": "D624",
"secondStr": "M2435"
},
{
"firstStr": "T4543",
"secondStr": "K9345"
}
]
This data is defined as ArrayList
. The objects inside array are defined as Map
:
Map<String,String> data = new HashMap();
data.put("firstStr","D392");
data.put("secondStr","N3895");
...
ArrayList<Map> insert = new ArrayList<Map>();
insert.add(data);
I need to map this data in sql template using <iterate>
(because in my version foreach is not available). What i currently have:
<select parameterClass="ArrayList">
select * from something
where str IN
<iterate property="insert">
#[].firstStr$, #[].secondStr#
</iterate>
</select>
I am getting the following error:
String index out of range: -1
What could be the cause of this problem?
EDIT: Dont ask me to update or to use another dependency because it is not possible due to software limitations!
Actually you are right, you just got one small typo in your code. Remove property="insert"
in your <iterate>
statement:
<select parameterClass="ArrayList">
select * from something
where str IN
<iterate>
#[].firstStr$, #[].secondStr#
</iterate>
</select>