You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user-java@ibatis.apache.org by Ashish Kulkarni <as...@gmail.com> on 2009/06/22 22:39:05 UTC

Question about Dynamic and iterator

HiI have to write a query like below

Select col1, col2 from table1 where col3='ABC' or col3='XYZ'

so i wrote a query like below, will this work, *what do i have  to specify
for property, *i have specified it as list, will this work, any suggestions

<select id="getMyInfi" resultClass="com.myclass.Table1"
parameterClass="java.util.List">

SELECT col1, col2 FROM table1
<dynamic prepend="where">
<iterate prepend="AND" *property="list" *
open="(" close=")" conjunction="OR">
col3=*#list[]#*
</iterate>
</dynamic>
</select>

or should i change it to

<parameterMap id="MyMap" class="java.util.Map">
<parameter property="id" javaType="java.util.List" />
</parameterMap>

<select id="getMyInfi" resultClass="com.myclass.Table1"
parameterMap="MyMap">

SELECT col1, col2 FROM table1
<dynamic prepend="where">
<iterate prepend="AND" *property="id" *
open="(" close=")" conjunction="OR">
col3=*#id[]#*
</iterate>
</dynamic>
</select>

RE: Question about Dynamic and iterator

Posted by Poitras Christian <Ch...@ircm.qc.ca>.
I would try
<select id="getMyInfi" resultClass="com.myclass.Table1"
parameterClass="java.util.List">

SELECT col1, col2 FROM table1
<dynamic prepend="where">
<iterate prepend="AND" property=""
open="(" close=")" conjunction="OR">
col3=#[]#
</iterate>
</dynamic>
</select>

But, you need to have a type handler registered for the objects in the list or #[]# will be replaced by toString(). If you list contains Strings or numeric values, it's ok.

Christian

________________________________
From: Ashish Kulkarni [mailto:ashish.kulkarni13@gmail.com]
Sent: Monday, June 22, 2009 4:39 PM
To: user-java@ibatis.apache.org
Subject: Question about Dynamic and iterator

Hi
I have to write a query like below

Select col1, col2 from table1 where col3='ABC' or col3='XYZ'

so i wrote a query like below, will this work, what do i have  to specify for property, i have specified it as list, will this work, any suggestions

<select id="getMyInfi" resultClass="com.myclass.Table1"
parameterClass="java.util.List">

SELECT col1, col2 FROM table1
<dynamic prepend="where">
<iterate prepend="AND" property="list"
open="(" close=")" conjunction="OR">
col3=#list[]#
</iterate>
</dynamic>
</select>

or should i change it to

<parameterMap id="MyMap" class="java.util.Map">
<parameter property="id" javaType="java.util.List" />
</parameterMap>

<select id="getMyInfi" resultClass="com.myclass.Table1"
parameterMap="MyMap">

SELECT col1, col2 FROM table1
<dynamic prepend="where">
<iterate prepend="AND" property="id"
open="(" close=")" conjunction="OR">
col3=#id[]#
</iterate>
</dynamic>
</select>