mybatis 批量更新 Parameter '__frch_item_0' not found. Available parameters are [list]


一次在做批量更新數據的時候報錯 Parameter '__frch_item_0' not found. Available parameters are [list] 記過反復查找,最后才發現是一個字段的字母小寫了。

下面給大家提供一個實例:

xml:這里說明一下這個sql的意思是根據h_code去更新h_clientA的值

<update id="updateHards" parameterType="java.util.List">
        <foreach collection="list" item="item" index="index" open="" close="" separator=";">
            update hard
            <set>
                <if test="item.h_clientA !=null">
                    h_clientA = #{item.h_clientA,jdbcType=VARCHAR}
                </if>
                <if test="item.h_clientB !=null">
                    h_clientB = #{item.h_clientB,jdbcType=VARCHAR}
                </if>
                <if test="item.h_clientC !=null">
                    h_clientC = #{item.h_clientC,jdbcType=VARCHAR}
                </if>
            </set>
            where h_code = #{item.hCode,jdbcType=VARCHAR}
        </foreach>
    </update>

 dao:

int updateHards(List<Hard> list);

 controller:

List<Hard> hards = new ArrayList<Hard>();
for (int i = 0; i < split.length; i++) {
            Hard hard = new Hard();
            switch (client.getClient_level()) {
                case 2:
                    hard.setH_clientB(h_client);
                    break;
                case 3:
                    hard.setH_clientC(h_client);
                    break;
    }
 
   hard.sethCode(split[i]);
   hards.add(hard);
 }
 // 3.進行操作,並返回
 
 int updateHards = hardManageService.updateHards(hards);

相關的錯誤信息:

1.查看parameterType的類型是不是java.util.List類型,如果是的話,看foreach 的collection屬性是不是list,

因為 傳遞一個 List 實例或者數組作為參數對象傳給 MyBatis,MyBatis 會自動將它包裝在一個 Map 中,用名稱在作為鍵。List 實例將會以“list” 作為鍵,而數組實例將會以“array”作為鍵 

2.看一下foreach里面的值有沒有傳遞進來 

3.看foreach里面的名稱字段是否寫錯 

4.還有就是我用Mybatis的時候,用mysql的值插入自動增長值,里面的key我在數據庫中沒有設置自動增長,然后我又用了selectkey,所以也會出現這種情況

如有需要可以加我Q群【308742428】大家一起討論技術。

后面會不定時為大家更新文章,敬請期待。

喜歡的朋友可以關注下。

  

 

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM