繁体   English   中英

MyBatis foreach与弹簧不起作用

[英]MyBatis foreach with spring not working

我正在尝试更新记录列表,但在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是我的列表。

请让我知道他们在我的查询中是否有任何错误。 为什么列表不录入? 各位,还有其他方法吗?

我建议您在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);

将您的类的列表名称放在collection属性中,将一个可选名称放在item属性中以在下面使用

您尝试以下代码:

<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