我的EsdTemplateSealMapper.java里面定義的接口是這樣的
public List<EsdTemplateSeal> getFilteOutSeal(@Param("filterList")List<String> list,@Param("templateId")String templateId);
然后我的EsdTemplateSealMapper.xml里面的sql是這樣的:
<select id="getFilteOutSeal" resultMap="BASE_RESULT_MAP"> select t.TEMPLATE_ID, t.SEAL_ID, t.SEAL_TYPE, t.DATA_SRC, t.VERSION from ESD_TEMPLATE_SEAL t where t.TEMPLATE_ID=#{templateId,jdbcType=VARCHAR} and t.SEAL_TYPE not in <foreach item="item" collection="list" separator="," open="(" close=")" index=""> #{0} </foreach> </select>
也寫過這樣的:
<select id="getFilteOutSeal" resultMap="BASE_RESULT_MAP"> select t.TEMPLATE_ID, t.SEAL_ID, t.SEAL_TYPE, t.DATA_SRC, t.VERSION from ESD_TEMPLATE_SEAL t where t.TEMPLATE_ID=#{templateId,jdbcType=VARCHAR} and t.SEAL_TYPE not in <foreach item="item" collection="list" separator="," open="(" close=")" index=""> #{filterList} </foreach> </select>
控制台都報類似:“
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'list' not found. Available parameters are [templateId, param1, param2, valueList]
”的問題,
最終的解決方案是:
<select id="getFilteOutSeal2" parameterType="map" resultMap="BASE_RESULT_MAP"> select t.TEMPLATE_ID, t.SEAL_ID, t.SEAL_TYPE, t.DATA_SRC, t.VERSION from ESD_TEMPLATE_SEAL t where t.TEMPLATE_ID=#{id} and t.SEAL_TYPE not in <foreach item="item" collection="filterList" separator="," open="(" close=")" index="index"> #{item} </foreach> </select>
ps:網上的解釋實在坑爹,根本原因就是他們根本就沒有理解foreach里面的collection應該放什么東西,錯誤的理解里面放的是java.util.List,其實這個類型應該是和我們的@Param綁定的參數名一致