踩坑記錄:Mybatis foreach用法需要注意的地方

今天在使用的時候,遇到了這個錯誤

Parameter ‘tagIdList’ not found. Available parameters are  [Collection,list] 

repository接口中

    public List<Tag> findAllById(List tagIdList);

mapper.xml中

<select id="findAllById" parameterType="java.util.List"  resultType="Tag" >
        select * from t_tag
        <where>
            <foreach item="id" separator="," collection="tagIdList" open="id in (" close=")">
                #{id}
            </foreach>
        </where>
    </select>

 

錯誤解決方法:接口中加上一個註解

public List<Tag> findAllById(@Param("tagIdList")List tagIdList);

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章