is the function method of the mapper interface:
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, #{1} represents the second parameter in the dao layer, and more parameters can be added later.
The second solution
is to use Map or create a new po class to store the filter conditions and pass multiple parameters.
The function method of the mapper interface
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 calls:
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, I think this method is not intuitive enough, seeing the interface method cannot directly know what the parameters to be passed are.
The third scheme
is the function method of the mapper interface:
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>
Personally, I think this method is better. It allows developers to see the dao layer method and know what parameters to pass. It is more intuitive, and I personally recommend this method.