list mybatis 接收 类型_MyBatis映射,用于在Oracle中获取自定义记录类型的列表

We are stuck with mybatis-mapping where we have to fetch list of Oracle Custom Record Types which is returned by a stored procedure.

Can anybody share sample code/mapping if you have any such cases implemented using mybatis.

Package

create or replace

package p1 as

TYPE T1 IS RECORD

(P_OBJECT_NAME VARCHAR2(80) ,

p_object_status VARCHAR2(25)) ;

TYPE t2 IS TABLE OF t1 index by BINARY_INTEGER;

procedure data_collection_append(t out t2);

procedure data_collection_extract;

end;

Package Structure

create or replace

PACKAGE BODY P1 AS

PROCEDURE DATA_COLLECTION_APPEND(t OUT t2) AS

cursor c1 is select object_name,status from user_objects where rownum = 1;

c c1%rowtype;

i number:=0;

begin

--t := t2() ;

open c1;

loop

fetch c1 into c;

EXIT WHEN C1%NOTFOUND;

dbms_output.put_line(c.object_name||'==>'||c.status);

T(I).P_OBJECT_NAME:=C.OBJECT_NAME;

t(i).p_object_status:=c.status;

i:=i+1;

end loop;

end;

procedure data_collection_extract as

t t2;

begin

data_collection_append(t);

for i in t.first..t.last

LOOP

dbms_output.put_line(t(i).p_object_name||'==>'||t(i).p_object_status);

end loop;

end;

END;

Mapping

DECLARE

v_custom_record p1.T2;

BEGIN

v_custom_record := p1.data_collection_append();

#{objectName, javaType=String, jdbcType=VARCHAR, mode=OUT} := v_custom_record.P_OBJECT_NAME;

END;

POJO

public class Detail {

String objectName;

String objectStatus;

// Getter and Setter Methods

}

Error --> indentified "P_OBJECT_NAME" not defined in T1.

Can anybody provide me a solution?

解决方案

Change the mapper as follows

{call p1.data_collection_append(#{objList, jdbcType=CURSOR, mode=OUT, resultMap=myResultMap, javaType=java.sql.ResultSet})}

create a type in SpInOut in you domain directory

public class SpInOut {

private Object objList;

//getter setting follows

}

Here is a complete simple example

DB side

Create custom type

PACKAGE KP_EMP_PCK AS

type empType is ref cursor;

END KP_EMP_PCK;

Create a stored procedure

create or replace PROCEDURE KPLISTEMP

( empList OUT kp_emp_pck.empType

) AS

BEGIN

open empList for select empid, fname, lname,address from kpemployee order by fname;

END KPLISTEMP;

Java Side

Create domain class

public class User {

private String fName;

private String company;

private int age;

private int salary;

//getter Setter

}

Create domain for SpInOut

public class SpInOut {

private Object empList;

//getter setting follows

}

Mapper interface

public interface EmployeeMapper {

void getEmployees(SpInOut param);

}

Mapper xml file

{call kplistemp(#{empList, jdbcType=CURSOR, mode=OUT, resultMap=empResultMap, javaType=java.sql.ResultSet})}

And finally the service class

public class EmployeeServiceImpl implements EmployeeService {

@Autowired

EmployeeMapper mapper;

@Override

public List getEmps() {

try{

SpInOut data= new SpInOut();

mapper.getEmployees(data);

return (List) data.getEmpList();

}catch(Exception e){

e.printStackTrace();

}

return null;

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值