Mybatis 传入多个参数的方法

来源:互联网 发布:kingcms php 编辑:程序博客网 时间:2024/05/01 01:42

1.由于是多参数那么就不能使用parameterType, 改用#{index}是第几个就用第几个的索引,索引从0开始

<update id="modifyPwd">        UPDATE ams_user         SET login_pwd = #{0}, update_time =#{1,jdbcType=TIMESTAMP}         WHERE user_id = #{2,jdbcType=INTEGER}</update>
  1. 通过注解的方式
    调用方法:
Integer modifyPwd(@Param("userId")Integer userId,@Param("pwd") String pwd,@Param("upTime") Date updateTime);

xml中的写法:

<update id="modifyPwd">        UPDATE ams_user         SET login_pwd = #{pwd}, update_time = #{upTime,jdbcType=TIMESTAMP}         WHERE user_id = #{userId,jdbcType=INTEGER}</update>

3.通过Map的方式传递多个参数
map中key的名字就是在#{}中使用的那个

Integer modifyPwd(HashMap map);  <update id="modifyPwd" parameterType="hashmap">UPDATE ams_user         SET login_pwd = #{pwd}, update_time = #{upTime,jdbcType=TIMESTAMP}         WHERE user_id =#{userId,jdbcType=INTEGER}  </update>  
1 0