The editor will share with you three solutions to solve the problem of mybatis passing multiple parameters. The specific introduction is as follows:
The first solution
Functional methods of DAO layer
Public User selectUser(String name,String area);
Corresponding Mapper.xml
<select id="selectUser" resultMap="BaseResultMap">select * from user_user_t where user_name = #{0} and user_area=#{1}</select>Among them, #{0} represents the first parameter in the dao layer, and #{1} represents the second parameter in the dao layer, and more parameters can be added consistently.
The second solution
This method uses Map to pass multiple parameters.
Function method of Dao layer
Public User selectUser(Map paramMap);
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","corresponds the specific parameter value");paramMap.put("userArea","corresponds the specific parameter value");User user=xxx. selectUser(paramMap);}I personally think that this method is not intuitive enough, and when you see the interface method, you cannot directly know what the parameters to be passed.
The third solution
Function method of Dao layer
Public User selectUser(@param("userName")Stringname,@param("userArea")String area);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>I personally think this method is better, and it allows developers to know what parameters to pass when they see the dao layer method. It is more intuitive. I personally recommend this solution.
The above is the solution to Mybatis passing multiple parameters introduced by the editor. I hope it will be helpful to everyone!