0
Spring Tool SuiteのMybatisを使用してテーブル型の値を返すoracleストアド関数を呼び出す際に問題が発生しました。私のコードを見て、私に答えてください。ありがとう。春にmybatisを使用してテーブルタイプを返すoracleストアド関数を呼び出す方法は?
最初は、これはOracle SQL Developerのコードです。
create or replace TYPE recommend_type as object
(
pno number,
productthumimage varchar2(500),
confidence number
);
/
create or replace TYPE recommend_table
as table of recommend_type;
/
create or replace function recommend_func
(p_startdata IN varchar2)
return recommend_table
is
r_type recommend_table := recommend_table();
v_conf tbl_confidence%rowtype;
cnt number;
v_pno tbl_product.pno%type;
v_productthumimage tbl_product.productthumimage%type;
v_confidence tbl_confidence.confidence%type;
CURSOR recommendcursor is
select *
from tbl_confidence
where STARTDATA = p_startdata;
BEGIN
open recommendcursor;
cnt := 1;
loop
fetch recommendcursor into v_conf.startdata, v_conf.enddata, v_conf.confidence;
exit when recommendcursor%NOTFOUND;
select pno, productthumimage into v_pno, v_productthumimage
from tbl_product
where PNO = v_conf.enddata;
v_confidence := v_conf.confidence;
r_type.extend;
r_type(cnt) := recommend_type(v_pno, v_productthumimage, v_confidence);
cnt := cnt+1;
end loop;
return r_type;
end;
/
次のように、結果の行をOracle SQL Developerに正常に取得できます。
select *
from table(recommend_func(38));
Mapper.xml春
<select id="getRecommedList" parameterType="org.ktl.domain.ConfidenceVO"
statementType="CALLABLE" >
{CALL RECOMMEND_FUNC
(
#{startdata, mode=IN, jdbcType=VARCHAR}
)
}
</select>
のJavaビーン - (ゲッター&セッター& toStringメソッドがスキップされる)パラメータとテーブル型の戻り値に がため
public class ConfidenceVO {
private String startdata;
private String enddata;
private Double confidence;
(... getter & setter)
}
public class RecommendVO {
Integer pno;
String productthumimage;
Double confidence;
(... getter & setter)
}
DAOコード
public List<RecommendVO> getRecommedList(ConfidenceVO confidenceVO) throws Exception {
// TODO Auto-generated method stub
return session.selectList(namespace+".getRecommedList", confidenceVO);
}
JUnitテストコード
@Test
public void getRecommedListTest() throws Exception {
ConfidenceVO cVO = new ConfidenceVO();
cVO.setStartdata("38");
System.out.println(dao.getRecommedList(cVO));
}//
エラーテキスト
ERROR: org.springframework.test.context.TestContextManager - Caught exception while allowing TestExecutionListener [org.springframewor[email protected]51081592] to prepare test instance [[email protected]]
java.lang.IllegalStateException: Failed to load ApplicationContext
This is the end. plz help me.
ご回答いただきありがとうございます。私は追加のテーブル(tbl_recommend)を追加し、プロシージャに関数を変更することで問題を解決しました。私は以下のようにmybatisを使用してOracleストアドプロシージャを呼び出すことができます。 <インサートID = "insertRecommedList" するStatementType = "CALLABLE"> \t \t \t CALLのrecommend_proc(#{STARTDATA}) とにかく本当に感謝。 – wjheo