【问题标题】:How to use select statement in iterate in IBATIS?如何在 IBATIS 的迭代中使用 select 语句?
【发布时间】:2014-10-30 07:35:05
【问题描述】:

MySQL查询如下

update  group_entity set deleted = 1  where entity_id in (select entity_id from entity where entity_row_id in ('1-424g','1-242T') and entity_type='Data');

此查询在 mysql 中有效。

我的 Ibatis 查询更改如下

<update id="updateData" parameterClass="abc.data.updateDataParameters">
    update group_entity set deleted = 1 where entity_id in
    <iterate open="(" close=")" conjunction=",">
        select entity_id from entity where entity_row_id in
         <iterate property="parentIds" open="(" close=")" conjunction=",">
            #parentIds[]#
        </iterate>
        and entity_type = #parentType#
    </iterate>
</update>

但 Ibatis 查询无法正常工作,出现错误 ParameterObject or property was not a Collection, Array or Iterator. 错误:

--- Cause: com.ibatis.sqlmap.client.SqlMapException: ParameterObject or property was not a Collection, Array or Iterator.; nested exception is com.ibatis.common.jdbc.exception.NestedSQLException:

请告诉我如何在迭代中使用 select 语句,如 &lt;iterate&gt;Select id from table&lt;/iterate&gt; 返回 id 列表。

我的更新数据参数

class updateDataParameters
{
List<String> parentId;
string parentType;
// with getter and setter and receptive constructor  
}

【问题讨论】:

    标签: java mysql spring spring-mvc ibatis


    【解决方案1】:

    第一个迭代元素不是必需的。 您的要求应该是:

    <update id="updateData" parameterClass="abc.data.updateDataParameters">
        update group_entity set deleted = 1 where entity_id in (
            select entity_id from entity where entity_row_id in
            <iterate property="parentId" open="(" close=")" conjunction=",">
                #parentId[]#
            </iterate>
            ) and entity_type = #parentType#
    </update>
    

    还有一个拼写错误:parentIds 应该是 parentId 才能匹配类属性。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-30
      • 2015-09-17
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多