You have a couple of options.
- Pass
a map as the parameterClass and add your User object, SortField, and
SortType to the map before calling the statement. The key names of the map
will match the names in the map.
- Create
a SortCriterion class with a SortField and SortType property and pass
multiple instances using a map (if you want to sort by multiple fields).
The map then looks like this:
<select id="SelectUser"
parameterClass="map" resultMap="UserResult">
...
<dynamic prepend="ORDER BY ">
<isNotEmpty property="SortField">
ORDER BY $SortField$ $SortType$
</isNotEmpty>
</dynamic>
</select>
From: Stief Dirckx
[mailto:[EMAIL PROTECTED]
Sent: Monday, August 21, 2006 1:45
AM
To: [email protected]
Subject: dynamic order by clause
Hi
I'm
having some questions about the dynamic sorting example in the iBatis
datamapper manual on page 51. What I want to do is is to pass an object to an
select statement but I also want to make the sorting dynamic (sort field and
sort type). But how can I pass these 2 extra parameters using the QueryForList
method?
This
is what I have up to now:
<select
id="SelectUser" parameterClass="User"
resultMap="UserResult">
...
<dynamic prepend="ORDER BY ">
<isNotEmpty property="SortField">
ORDER BY $SortField$ $SortType$
</isNotEmpty>
</dynamic>
</select>
But
with this solution I have to add 2 properties to my user class (sortfield and
sorttype). How can I avoid doing that?
Stief.
|