1

我正在尝试更新记录列表,但在 mybatis 中出现以下错误。

 org.apache.ibatis.reflection.ReflectionException: There is no getter for property named 'list' in 'class com.model.DataParameters'

我的 mybatis xml 查询如下

<update id="deleteAssociatedEntityForParentEntity" parameterType="com.model.DataParameters">
    update dataTable set deleted = #{deleted}, syncTS = #{syncTS} where
    data_id in
    <foreach item="dataIds" index="index" collection="list"
        open="(" separator="," close=")">
        #{dataIds}
    </foreach>
    and aData_type = #{dataType};

</update>

DataParameter 类 getter setter 已在此类中声明。dataIds 是我的清单。

请让我知道他们在我的查询中是否有任何错误。为什么列表不包含?伙计们还有什么办法吗?

4

2 回答 2

0

将您的类列表名称放在集合属性中,并在项目属性中使用可选名称以在下面使用

你试试这个代码:

<update id="deleteAssociatedEntityForParentEntity" parameterType="com.model.DataParameters">
    update dataTable set deleted = #{deleted}, syncTS = #{syncTS} where
    data_id in
    <foreach item="id" index="index" collection="dataIds"
        open="(" separator="," close=")">
        #{id}
    </foreach>
    and aData_type = #{dataType};

</update>
于 2014-12-15T11:12:16.037 回答
0

我建议您在 foreach .. dataIds 应该是 List 之前进行一些额外的检查。

<update id="deleteAssociatedEntityForParentEntity" parameterType="com.model.DataParameters">
   update dataTable set deleted = #{deleted}, syncTS = #{syncTS} where 1=1
   <if test="dataIds!= null">
        and data_id in
        <foreach item="item" index="index" collection="dataIds"
        open="(" separator="," close=")">
        #{item}
        </foreach>
    </if>
   and aData_type = #{dataType};
</update>

这只是一小段代码

SqlSession session = sessionFactory.openSession();

Map<String, Object> mapParameter = new HashMap<String, Object>();
List<Integer> listDataIds = ....

mapParameter.put("dataIds",listDataIds );

session.update("deleteAssociatedEntityForParentEntity",mapParameter);
于 2014-12-15T10:18:13.633 回答