简体   繁体   English

存储过程输出参数由iBATIS设置回POJO

[英]Stored procedure output parameter set back to POJO by iBATIS

I'm using iBATIS to call a Stored Procedure on MSSQL Server, the input parameters are properties on a POJO that is put to the map: 我正在使用iBATIS在MSSQL Server上调用存储过程,输入参数是放在地图上的POJO上的属性:

Map<String, Object> saveMap = new HashMap<String, Object>();
saveMap.put("obj", myArticle);
update("save", saveMap);

All parameters are set correctly as input to the procedure so nothing wrong there. 所有参数都正确设置为过程的输入,因此没有任何错误。 But one of the parameters is a output-parameter and and I was expecting it to be set back to the POJO but instead one extra mapping "obj.new"=false is put the map by iBATIS. 但其中一个参数是一个输出参数,而且我期望它被设置回POJO,而是一个额外的映射"obj.new"=false由iBATIS放置地图。 Here's a simplified version of the mapping showing the basic idea: 这是映射的简化版本,显示了基本思想:

    <procedure id="save">
    {<include refid="Core.returned_value" />
    CALL SPRC_ARTICLE_NAME_SAVE (
        <include refid = "Core.common_fields" />
        @pArticle_id = #obj.art_id#
    ,   @pArtname = #obj.artname#
    ,   @pNewArticleName_flg = #obj.new,mode=INOUT#
    )}
</procedure>

After calling the procedure I have two mappings in Map passed to iBATIS: 调用该过程后,我在Map中传递给iBATIS的两个映射:

  • "obj"=POJO
  • "obj.new"=False

Now I see that iBatis documentation saids "When executing stored procedures – iBATIS will create objects for OUTPUT parameters" so it makes sense. 现在我看到iBatis文档“当执行存储过程时 - iBATIS将为OUTPUT参数创建对象”,所以它是有道理的。 But my question is if there a way to instruct iBATIS put back the boolean value to the POJO after the procedure is called? 但我的问题是,有没有办法指示iBATIS在调用过程后将布尔值放回到POJO? I rather don't do the extra work of getting the value out of the map and set it to the POJO my self. 我宁愿不做额外的工作,从地图中获取价值并将其设置为我自己的POJO。

// Uhlén //Uhlén

You can using an explicit parameter map. 您可以使用显式参数映射。 See Page 21 of the manual 请参见手册的第21页

Its rather verbose but its worked for me in the past. 它相当冗长,但它在过去对我有用。

<parameterMap id="swapParameters" class="map" >
    <parameter property="email1" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
    <parameter property="email2" jdbcType="VARCHAR" javaType="java.lang.String" mode="INOUT"/>
</parameterMap>

<procedure id="swapEmailAddresses" parameterMap="swapParameters" >
    {call swap_email_address (?, ?)}
</procedure>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM