Use Mybatis to pass multiple parameters (three solutions) and mybatis Solution
There are three methods to transmit multiple parameters that I have come into contact.
Solution 1
DAO layer Function Method
Public User selectUser(String name,String area);
Corresponding er. xml
<select id="selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{0} and user_area=#{1}</select>
# {0} indicates that the first parameter in the dao layer is received, and # {1} indicates the second parameter in the dao layer. More parameters are added after they are consistent.
Solution 2
This method uses Map to transmit multiple parameters.
Dao layer Function Method
Public User selectUser(Map paramMap);
Corresponding er. 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 specific parameter values"); paramMap. put ("userArea", "corresponds to specific parameter values"); User user = xxx. selectUser (paramMap );}
I personally think this method is not intuitive enough. When you see an interface method, you cannot directly know what parameters you want to transmit.
Solution 3 Function Method of Dao Layer
Public User selectUser(@param(“userName”)Stringname,@param(“userArea”)String area);
Corresponding er. xml
<select id=" selectUser" resultMap="BaseResultMap"> select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}</select>
I personally think this method is better, so developers can see what parameters should be passed in the dao layer method, which is more intuitive. I personally recommend this method.
How many parameters does mybatis pass?
Mybatis has never been used, and Ibatis has been used for a while.
The error is that you passed in.
Map. put ("productType", );
The productType parameter cannot be found.
If the parameter is not passed in, you can consider adding a dynamic Where condition to getScrollPage.
References: x
How does MyBatis pass multiple parameters?
In MyBatis, you can use the following method to pass multiple parameters: 1. use java. util. the Code is as follows: public List getAllUsersByUserName (String username, int start, int limit) {Map params = new HashMap (3); params. put ("username", username); params. put ("start", start); params. put ("limit", limit); return userMapper. getAllUsersByUserName (params);} corresponding XXMapper. the xml file is as follows: SELECT u. * FROM User u WHERE u. username LIKE # {username} '%' LIMIT # {start}, # {limit} 2. the Code is as follows: public List getUsersByUserName (String username) {User user User = new user (); User. setUsername (username); return userMapper. getUserByUsername (user);} corresponding XXMapper. the xml file is as follows: SELECT u. * FROM User u WHERE u. username = # {username} OK. Let's introduce these two methods !!!