Mybatis 傳入多個引數的方法
阿新 • • 發佈:2018-12-31
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>
- 通過註解的方式
呼叫方法:
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>