一、报错代码
- Dao接口方法
public List<User> findInIds(List<Integer> ids);
- Mapper配置
<select id="findInIds" resultType="com.itheima.domain.User">
select * from user
<where>
<if test="ids != null and ids.size() > 0">
<foreach collection="ids" open="and id in (" close=")" item="id" separator=",">
#{id}
</foreach>
</if>
</where>
</select>
-
以上代码运行时,会抛出如下异常,异常信息:
org.apache.ibatis.binding.BindingException: Parameter ‘ids’ not found.
二、解决方法
- 在接口方法中的参数前加上@Param注解,为参数取个名字,便可以解决上述问题
public List<User> findInIds(@Param("ids") List<Integer> ids);