Method for displaying several iBatis parameters

Let's say I have a getUser request with two parameters - userName and password. I would like to have a mapper method that looks like this:

 public UserBean getUser(String userName, String password); 

Is there a way to achieve something like this? Or maybe I need to pass the mapper parameter parameter map (and some Map parameter in my XML editor)?

 public UserBean getUser(Map<String, Object> paramMap); 

I look forward to some tips and explanations.

+6
ibatis mapper
source share
2 answers

Without any special configuration, you can refer to the first and second parameters as # {1} and # {2} respectively.

If you want to name the parameters and not refer to them numerically, do the following: In the XML mapping for the SELECT statement, set the Type = "map" parameter and in the interface file, annotate the parameters with @Pairs. For example, public UserBean getUser (@Param ("username" String userName, @Param ("password") String password) will allow you to refer to the username and password in the XML mapping as # {username #} and # {password}, Accordingly.

+9
source share

You should not change the signature of your DAO method, the only problem to consider is how you create your mapping. iBatis supports only one input parameter, and you have to solve your class ( parameterType attribute) to pack two source parameters into one.

In this case, you can (among other parameters) put two parameters in the Map ( HashMap , as a rule), or (if the parameters correspond to the properties of the UserBean class) pass a dummy UserBean with these two properties.

In both cases, packaging (creating a HashMap or a dummy UserBean that contains two parameters) will be done inside your public UserBean getUser(String userName, String password) method.

+1
source share

All Articles