first option
Function method 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, #{1} represents the second parameter in the dao layer, and more parameters can be added later.
The second option
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", "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 option
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>
Personally, I think this method is better. It allows developers to know what parameters to pass when they see the dao layer method. It is more intuitive, and I personally recommend this method.