一、传入参数为HashMap使用方法
1、在mapper中配置如下:

在 mapper 配置 parameterType = “HashMap” 并在接口中创建一个方法参数为Map(或HashMap)

2、调用

二、调用存储过程
1、在 mysql中创建存储过程
CREATE PROCEDURE `updateUserById`(IN userId int, OUT updateRows int )
BEGIN
select count(1) into updateRows from userinfo where id=userId;
END
2、配置mapper(注意有些jdbc驱动不支持换行)
statementType 必须声明为 CALLABLE ,传入参数为 HashMap
<select id="updateUserById_Procedure" statementType="CALLABLE" parameterType="HashMap" >
{call updateUserById (#{userId,jdbcType=INTEGER,mode=IN},#{updateRows,jdbcType=INTEGER,mode=OUT})}
</select>
3、在mapper中创建方法
void updateUserById_Procedure(Map map);
4、调用
获取返回值通过 map.get(“updateRows”) 获取
private static void updateUserById_Procedure(UserMapper mapper,SqlSession sqlSession) {
Map<String,Object> map =new HashMap<>();
map.put("userId",4);
mapper.updateUserById_Procedure(map);
System.out.println(map.get("updateRows"));
}
MyBatis使用HashMap参数及调用存储过程教程
本文介绍了在MyBatis中如何使用HashMap作为传入参数,并详细讲解了调用存储过程的步骤,包括在mapper中的配置、在MySQL创建存储过程、设置statementType为CALLABLE以及如何获取返回值。
1091





