Let's say I have a query getUser
with two parameters - userName and password. I'd like to have a mapper method looking like this:
public UserBean getUser(String userName, String password);
Is there any way I can achieve something like that? Or maybe I should pass in my mapper method map of parameters (and some parameterMap in my xml mapper)?
public UserBean getUser(Map<String, Object> paramMap);
I'm looking forward for some hints and explanations.
Without any special configuration, you can refer to the first and second parameter as #{1} and #{2}, respectively.
If you would like to name the parameters, rather than referring to them numerically, do the following: In the XML mapping for your SELECT statement, set parameterType="map", and in the interface file, annotate the parameters with @Param. For example, public UserBean getUser( @Param( "user_name" String userName, @Param( "password" ) String password); would allow you to refer to the username and password, in the XML mapping, as #{user_name#} and #{password}, respectively.