其实无论是返回以下哪种类型,其实都是键值对 对的形式
普通类型
oracle(即存储过程)
create or replace procedure testReturnResult(returnResult out varchar2)
as
begin
returnResult :='返回结果';
end ;
java
service:
Map<String,Object> mm=new HashMap<String,Object>();
this.j1SchedulingDao.testReturnResult(mm);
System.out.println("returnResult:"+mm.get("returnResult"));
dao:
public void testReturnResult(Map mm) throws SQLException;
mybatis
<select id="testReturnResult" parameterType="java.util.Map" statementType="CALLABLE">
{call testReturnResult(#{returnResult, mode=OUT, jdbcType=VARCHAR})}
</select>
游标类型
oracle(即存储过程)
create or replace procedure testReturnList(returnList out sys_refcursor)
as
begin
open returnList for select * from T_J1_SCHEDULING;
end ;
java
service:
Map<String,Object> mmap=new HashMap<String,Object>();
this.j1SchedulingDao.testReturnList(mmap);
List<Map<String,Object>> returnList = (List<Map<String, Object>>) mmap.get("returnList");
dao:
public void testReturnList(Map mm) throws SQLException;
mybatis
<select id="testReturnList" parameterType="java.util.Map" statementType="CALLABLE">/*resultMap=BaseResultMap*/
{call testReturnList(#{returnList, mode=OUT,jdbcType=CURSOR,resultMap=com.wonders.yyzl.dao.J1SchedulingDao.BaseResultMap})}
</select>
踩过的坑
The JDBC Type must be specified for output parameter. Parameter: returnResult 必须指定jdbcType Parameters of type java.sql.ResultSet require a resultmap. 如果返回值是游标类型 必须指定resultmap BaseResultMap is ambiguous in Result Maps collection (try using the full name including the namespace, or rename one of the entries) 需要指定包,指向对应的dao包 也就是当前的namespace.resultMap的id就可以了
[写博客只为记录,如有不对,还请各位大佬指出]