本文转载至http://www.cnblogs.com/baby-lijun/p/5908088.html
我的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绑定的参数名一致