mybatis传递多个参数的三种方式

记录一下,老是记不全。

一、

Dao层方法:

Public User selectUser(String name,String area);

 

对应的Mapper.xml :

<select id="selectUser" resultMap="BaseResultMap">
    select  *  from user_user_t   where user_name = #{0} and user_area=#{1}
</select>

二、

Dao层方法:

Public User selectUser(Map paramMap);

对应的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层:

Private User xxxSelectUser(){
Map paramMap=new hashMap();
paramMap.put(“userName”,”对应具体的参数值”);
paramMap.put(“userArea”,”对应具体的参数值”);
User user=xxx. selectUser(paramMap);}

三、

Dao层方法:

Public User selectUser(@param(“userName”)Stringname,@param(“userArea”)String area);

对应的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>

 

很简单的啦!     =_=

posted @ 2019-10-11 16:56  也许没资格  阅读(645)  评论(1编辑  收藏  举报