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 Nicolas ANTONIAZZI <ni...@gmail.com> on 2010/05/17 12:15:26 UTC

ibatis3 : multiple parameters in statement without map or bean

Hi,

Is it possible to pass multiple parameters in iBatis3 without having to pass
a map or a bean ?

example :
------------- UserMapper.xml ------------
<select id="selectUsers" parameterType="hashmap" resultType="List<User>">
  SELECT * FROM user OFFSET #{offset} LIMIT #{limit}
</select>

------------- UserMapper.java -----------
public interface UserMapper {
  public List<User> selectUsers(HashMap<String, Integer> parameters);
}
-----------------------------------------

Now, I can call my statement with :


int offset = 10;
int limit = 10;

UserMapper userMapper = session.getMapper(UserMapper.class);
HashMap<String, Integer> parameters = new HashMap<String, Integer>();
parameters.put("offset", offset);
parameters.put("limit", limit);
List<Question> selections = questionMapper.selectQuestions(parameters);

------------------------------------------

I think that a cleaner way would be to do somethink like :

public interface UserMapper {
  public List<User> selectUsers(int offset, int limit);
}

UserMapper userMapper = session.getMapper(UserMapper.class);
List<Question> selections = questionMapper.selectQuestions(10, 10);

-------------------------------------------

Is there such a method to achieve it with iBatis 3 ?

Thanks,

Nicolas ANTONIAZZI.

Re: ibatis3 : multiple parameters in statement without map or bean

Posted by Nicolas ANTONIAZZI <ni...@gmail.com>.
Thank you Larry, I did not read correctly the User Guide.

Indeed, it says :

*If your mapper method takes multiple parameters, this annotation can be
applied to a mapper method parameter to give each of them a name. Otherwise,
multiple parameters will be named by their ordinal position (not including
any RowBounds parameters). For example #{1}, #{2} etc. is the default. With
@Param(“person”), the parameter would be named #{person}.*

Thanks.

2010/5/17 Larry Meadors <la...@gmail.com>

> Yes, you have to annotate the parameters (because java reflection is
> kinda weak).
>
> It's in the user guide.
>
> Larry
>
>
> On Mon, May 17, 2010 at 4:15 AM, Nicolas ANTONIAZZI
> <ni...@gmail.com> wrote:
> > Hi,
> > Is it possible to pass multiple parameters in iBatis3 without having to
> pass
> > a map or a bean ?
> > example :
> > ------------- UserMapper.xml ------------
> > <select id="selectUsers" parameterType="hashmap" resultType="List<User>">
> >   SELECT * FROM user OFFSET #{offset} LIMIT #{limit}
> > </select>
> > ------------- UserMapper.java -----------
> > public interface UserMapper {
> >   public List<User> selectUsers(HashMap<String, Integer> parameters);
> > }
> > -----------------------------------------
> > Now, I can call my statement with :
> >
> > int offset = 10;
> > int limit = 10;
> > UserMapper userMapper = session.getMapper(UserMapper.class);
> > HashMap<String, Integer> parameters = new HashMap<String, Integer>();
> > parameters.put("offset", offset);
> > parameters.put("limit", limit);
> > List<Question> selections = questionMapper.selectQuestions(parameters);
> > ------------------------------------------
> > I think that a cleaner way would be to do somethink like :
> > public interface UserMapper {
> >   public List<User> selectUsers(int offset, int limit);
> > }
> > UserMapper userMapper = session.getMapper(UserMapper.class);
> > List<Question> selections = questionMapper.selectQuestions(10, 10);
> > -------------------------------------------
> > Is there such a method to achieve it with iBatis 3 ?
> > Thanks,
> > Nicolas ANTONIAZZI.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
> For additional commands, e-mail: user-java-help@ibatis.apache.org
>
>

Re: ibatis3 : multiple parameters in statement without map or bean

Posted by Larry Meadors <la...@gmail.com>.
Yes, you have to annotate the parameters (because java reflection is
kinda weak).

It's in the user guide.

Larry


On Mon, May 17, 2010 at 4:15 AM, Nicolas ANTONIAZZI
<ni...@gmail.com> wrote:
> Hi,
> Is it possible to pass multiple parameters in iBatis3 without having to pass
> a map or a bean ?
> example :
> ------------- UserMapper.xml ------------
> <select id="selectUsers" parameterType="hashmap" resultType="List<User>">
>   SELECT * FROM user OFFSET #{offset} LIMIT #{limit}
> </select>
> ------------- UserMapper.java -----------
> public interface UserMapper {
>   public List<User> selectUsers(HashMap<String, Integer> parameters);
> }
> -----------------------------------------
> Now, I can call my statement with :
>
> int offset = 10;
> int limit = 10;
> UserMapper userMapper = session.getMapper(UserMapper.class);
> HashMap<String, Integer> parameters = new HashMap<String, Integer>();
> parameters.put("offset", offset);
> parameters.put("limit", limit);
> List<Question> selections = questionMapper.selectQuestions(parameters);
> ------------------------------------------
> I think that a cleaner way would be to do somethink like :
> public interface UserMapper {
>   public List<User> selectUsers(int offset, int limit);
> }
> UserMapper userMapper = session.getMapper(UserMapper.class);
> List<Question> selections = questionMapper.selectQuestions(10, 10);
> -------------------------------------------
> Is there such a method to achieve it with iBatis 3 ?
> Thanks,
> Nicolas ANTONIAZZI.

---------------------------------------------------------------------
To unsubscribe, e-mail: user-java-unsubscribe@ibatis.apache.org
For additional commands, e-mail: user-java-help@ibatis.apache.org