简体   繁体   English

MyBatis foreach与弹簧不起作用

[英]MyBatis foreach with spring not working

I am Trying to update list for records but i got the following error in mybatis. 我正在尝试更新记录列表,但在mybatis中遇到以下错误。

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

and my mybatis xml query is as follow 和我的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 class getter setter has been declared in this class. DataParameter类的getter setter已在此类中声明。 dataIds is my list. dataIds是我的列表。

please let me know if is their any wrong in my query. 请让我知道他们在我的查询中是否有任何错误。 why list is not taking in? 为什么列表不录入? Any other way Guys ? 各位,还有其他方法吗?

I suggest you some additional check before the foreach .. dataIds should be List. 我建议您在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>

This is only a snippet of code 这只是一小段代码

SqlSession session = sessionFactory.openSession();

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

mapParameter.put("dataIds",listDataIds );

session.update("deleteAssociatedEntityForParentEntity",mapParameter);

Put your list name of class in collection attribute and an opcional name in item attribute to use below 将您的类的列表名称放在collection属性中,将一个可选名称放在item属性中以在下面使用

you try this code: 您尝试以下代码:

<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>

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

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