0

I know that we can pass list/string array in clause statement, like the below code

from here

Please advise me how can we pass more than parameter with IN clause in iBatis.

unknown
  • 643
  • 4
  • 15
  • 38
  • i means that the query should be like WHERE username IN #[]# and user_first_name=#user_first_name:CHAR# and user_last_name=#user_lst_name:CHAR# – unknown Jul 18 '14 at 10:08
  • `how can we pass more than parameter` more than what.? `more than parameter` its hard to understand please explain – Saif Sep 08 '14 at 09:42

1 Answers1

0

This is possible.

Define a class for holding your input, which will hold your three properties that are needed for the Select, so they might be:

  • FirstName (string)
  • LastName (string)
  • UserNames (list of strings)

If you were using C#, it might look something like this:

public class UserRetrievalParams
{
    public String FirstName { get; set; }
    public String LastName { get; set; }
    public IList<String> UserNames { get; set; }
}

...or something similar. Construct an instance of that object and populate the list with your usernames.

Then pass that object into Ibatis as the parameter, and you can reference the properties like this:

<select id="example" resultMap="yourMap" parameterClass="UserRetrievalParams">
    select * from YourTable where

    username in
    <iterate property="UserNames" open="(" close=")" conjunction=",">
        #UserNames[]:char#
    </iterate>

    and user_first_name=#FirstName:char#
    and user_last_name=#LastName:char#
</select>

Note the slightly counter-intuitive syntax of having to reference the UserNames list property in two places: both in the iterate property, and again between the iterate tags.

I'm using this syntax successfully with Ibatis version 1.6.2.0 on .Net 2 and above.

Hope that helps.

Andrew B
  • 364
  • 5
  • 6