mybatis calls the stored procedure and obtains the return value

mybatis calls the stored procedure and obtains the return value

The return result of the stored procedure is directly placed in the map of the incoming parameter (paramCusKey)

Before calling {INPARA=CUSTOMER_KEY=545}

after calling

{OUTPARA=CUS_USER_ID=E00000049_02, INPARA=CUSTOMER_KEY=545}

 //Similar to using the built-in insertion method of mybatis to automatically return the primary key , (if there is a set primary key before, it will not return the inserted value, directly the set value ,) Return the output parameter of the stored procedure

 <select id="getCusKey" parameterType="map" statementType="CALLABLE" resultType="string">

  

  <![CDATA[  

    {call PD_OPT_ID(#{INPARA,mode=IN,jdbcType=VARCHAR},#{ OUTPARA, mode=OUT,jdbcType=VARCHAR})}  //Here is the field in the map where the stored procedure receives the returned result

  ]]>  

  

  </select>

 

 

public String getCusKey(Map<String,Object> param);

 

 

  

 

 

  Map<String,Object> paramCusKey = new HashMap<String,Object>();

paramCusKey.put("INPARA", "CUSTOMER_KEY="+tbCusUserBeanVo.getCustomerKey());

tbCusUserDao.getCusKey(paramCusKey);

String out=paramCusKey.get("OUTPARA").toString().substring(paramCusKey.get("OUTPARA").toString().indexOf("=")+1, paramCusKey.get("OUTPARA").toString().length());//获取结果

System.out.println(out);

System.out.println(paramCusKey.get("OUTPARA").toString());

 

 

 

===================================

//mybatis调用存储过程的另一xml写法

<parameterMap type="java.util.Map" id="recommendMap">

         <parameter property="inpara" mode="IN" jdbcType="VARCHAR"/>

         <parameter property="outpara" mode="OUT" jdbcType="VARCHAR"/>

     </parameterMap>

     

<select id="recommend" parameterMap="recommendMap" statementType="CALLABLE">

 

<![CDATA[

           call PD_CON_OBJ_RECOMMEND(?,?)    

       ]]>

 

</select>

 

 

@Override

public String recommend(String conobjKey) {

  StringBuffer inparasb = new StringBuffer("");

      inparasb.append("CONOBJ_KEY=");

      inparasb.append(conobjKey);

      inparasb.append('\r');

      inparasb.append('\n');

      inparasb.append("RECOMMEND_NAME=");

      inparasb.append("");

      String inpara = inparasb.toString();

      Map<String,String> map = new HashMap<String,String>();

      map.put("inpara", inpara);

      tbConObjMapper.recommend(map);

      return map.get("outpara");

}

 

public String recommend(Map<String,String> map);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326498099&siteId=291194637