mybatis 调用存储过程

第一步,在oracle数据库中创建存储过程
create or replace procedure pro_test(ename varchar2,
result out varchar2
)
as
begin
result:='hello,'||ename;
end;
第二步,在dao接口中声明调用存储过程的方法
第三步,在mapper中实现该方法
第四步,测试
/**
* 调用存储过程
*/
public class Test04 {
public static void main(String[] args) {
SqlSession session = SqlSessionFactoryUtil.getSession();
EmpDao empDao = session.getMapper(EmpDao.class);
//声明Map
Map<String,Object> map = new HashMap<String,Object>();
//传递入参
map.put("ename","zhangsan");
//设置出参,出参的值暂时设置为null
map.put("result",null);
//调用存储过程
empDao.testPro(map);
//存储过程调用之后,map中的出参就有值了
System.out.println("result:"+map.get("result"));
session.close();
}
}
原文地址:https://www.cnblogs.com/duguangming/p/10889625.html