Mybatis passes multiple parameters

 

Option One

  Function method of Dao layer

   1 Public User selectUser(String name,String area); 

   Corresponding Mapper.xml

1 <select id=" selectUser" resultMap="BaseResultMap">
2     select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
3 </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.

 

Option 2 (Map pass value)

  Function method of Dao layer

   1 Public User selectUser(Map paramMap); 

  Corresponding Mapper.xml 

1 <select id=" selectUser" parameterType="map" resultMap="BaseResultMap">
2     select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
3 </select>

Service layer call

1  Private User xxxSelectUser(){
 2      Map paramMap = new hashMap();
 3      paramMap.put("userName","corresponding to the specific parameter value");
 4      paramMap.put("userArea","corresponding to the specific parameter value" );
 5      User user= xxx. selectUser(paramMap);
 6 }

 

 

Option 3 (recommended)

  Function method of Dao layer

    1 Public User selectUser(@Param(“userName”) String name,@Param(“userArea”) String area); 

  Corresponding Mapper.xml

1 <select id=" selectUser" parameterType="map" resultMap="BaseResultMap">
2     select * from user_user_t where user_name = #{userName,jdbcType=VARCHAR} and user_area=#{userArea,jdbcType=VARCHAR}
3 </select> 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324610816&siteId=291194637