Small knitting for everyone to share three solutions to solve the problem of MyBatis pass multiple parameters, the specific description as follows:
First Scenario
The function method of DAO layer
Public User Selectuser (String name,string area);
The corresponding Mapper.xml
<select id= "Selectuser" resultmap= "Baseresultmap" >
select * from user_user_t where user_name = #{0} and User_ar Ea=#{1}
</select>
Where #{0} represents the first parameter in the DAO layer, #{1} represents the second parameter in the DAO layer, and more arguments are added consistently.
The second option
This method uses map to transmit multiple parameters.
The function method of DAO layer
Public User Selectuser (Map parammap);
The corresponding Mapper.xml
<select id= "Selectuser" resultmap= "Baseresultmap" >
select * from user_user_t where user_name = #{username, Jdbctype=varchar} and User_area=#{userarea,jdbctype=varchar}
</select>
Service Layer Call
Private User Xxxselectuser () {
Map parammap=new hashMap ();
Parammap.put ("UserName", "corresponding to the specific parameter value");
Parammap.put ("Userarea", "corresponding to the specific parameter value");
User user=xxx. Selectuser (PARAMMAP);}
Personally think this method is not intuitive enough to see the interface method can not directly know what to pass the parameters.
The third type of programme
The function method of DAO layer
Public User Selectuser (The @param ("UserName") Stringname, @param ("Userarea") String area);
The corresponding Mapper.xml
<select id= "Selectuser" resultmap= "Baseresultmap" >
select * from user_user_t where user_name = #{username, Jdbctype=varchar} and User_area=#{userarea,jdbctype=varchar}
Personally think this method is better, can let the developer see DAO layer method to know what kind of parameters to pass, more intuitive, personal recommend this kind of scheme.
The above is a small series to introduce the MyBatis to pass multiple parameters of the solution, I hope to help you!