The first scenario, passed by ordinal
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_area=#{1}</select>
Where #{0} represents the first parameter in the DAO layer, #{1} represents the second parameter in the DAO layer, and more parameters are consistently added.
The second scenario, passing through map
This method uses map to pass 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 Invocation
Private User Xxxselectuser () {Map parammap=new hashMap ();p arammap.put ("UserName", "corresponding to specific parameter values");p arammap.put ("Userarea "," corresponding to the specific parameter value "); User user=xxx. Selectuser (PARAMMAP);}
Personally, this method is not intuitive enough to see the interface method can not directly know what parameters to pass.
The third scenario, passed by a single parameter name with @param, is recommended
The function method of DAO layer
Public User Selectuser (@param ("UserName") Stringname, @param ("Userarea") of 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}</select>
The fourth scheme, passed through the parameter object with @param
The function method of DAO layer
Public User Selectuser (@param ("user") user user, @param ("Userarea") of String area);
The corresponding Mapper.xml
<select id= "Selectuser" resultmap= "Baseresultmap" > Select * from user_user_t where user_name = #{user.username, Jdbctype=varchar} and User_area=#{userarea,jdbctype=varchar} </select>
In each of these ways, you do not need to write the ParameterType property in XML
MyBatis passing parameters to Mapping.xml