MyBatis Call stored procedure return cursor instance

Source: Internet
Author: User
Tags stored procedure example
SQL view plain copy stored procedure example: Createor replace procedureFSP_PLAN_CHECKPRJ (V_grantno varchar2, v_deptcode number, v_cursor outSys_refcursor) is...---Return to the results of a statistic, or .... OpenV_cursor for SelectS.plan_code, S.plan_dept, S.plan_amount, S.exec_amount, p. CName asPlan_name, D.cname asDept_name fromSNAP_PLAN_CHECKPRJ s left join V_plan p onS.plan_code = P.plan_code LEFT join Org_office D onS.plan_dept = D.off_org_code Group byS.plan_code, S.plan_dept, S.plan_amount, S.exec_amount, P.cname, D.cname; End; EndFSP_PLAN_CHECKPRJ;

MyBatis: (MyBatis doc Api:http://mybatis.github.io/mybatis-3/zh/sqlmap-xml.html#result_maps)

Java layer Code [Java] View plain copy map<string, object> params = new hashmap<string, object> (); grantsetting GS = this.   Grantsettingdao.get (Grantcode);   Params.put ("Grantno", stringutils. Substring (gs.getgrantno (), 0, 2));      Params.put ("Offorgcode", Securityutils.getpersonofforgcode ()); Params.put ("V_cursor", new arraylist<map<string, object>> ());//pass in a JDBC cursor to receive the return parameter this  . Batisdao. Getsearchlist ("Call_fsp_plan_checkprj", params);

MyBatis XML configuration [HTML] view plain copy<ResultmapType = "Java.util.HashMap" id= "Cursormap"><。 --Configuration returns the Resultmap for the alias in the cursor-->< ResultColumn = "Plan_code" property= "Plan_code"/>< ResultColumn = "plan_dept" property= "plan_dept"/>< ResultColumn = "Plan_amount" property= "Plan_amount"/> < ResultColumn = "Exec_amount" property= "Exec_amount"/>< ResultColumn = "Plan_name" property= "Plan_name"/>< ResultColumn = "Dept_name" property= "Dept_name"/></Resultmap><Selectid = "CALL_FSP_PLAN_CHECKPRJ" parametertype= "map" statementtype= "callable">                                                               <!--Annotated statementtype= "callable" means invoking the stored procedure-->       &NBSP;&NBSP;{CALL&NBSP;FSP_PLAN_CHECKPRJ (#{grantno, jdbctype=varchar, mode=in},                                        #{offorgcode,  jdbcType=INTEGER, mode=IN},        #{v_cursor, mode=out,  jdbctype=cursor, resultmap=cursormap})}   <!--incoming outgoing parameters to indicate mode=in/out  and to note jdbctype (online can query MyBatis support which JdbctypeType), return the parameter to indicate the corresponding resultmap-->   </Select>
Finally, just iterate through the JSP page
Params.put ("V_cursor", Oracletypes. CURSOR); V_cursor in the middle. itself is a traversal of the list result set

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.