[英]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.