Parameter 'xxx' not found. Available parameters are [collection, list]

mybatis报错问题:

dao层:
List<HqjTrade> queryHongbao(ArrayList<String> listType);

映射文件下sql:
<select id="queryHongbao" resultType="HqjTrade" >
  select * from hqj_trade where tradetype in
      <foreach collection="listType" open="(" close=")" separator="," 
          item="tradetype">
              #{tradetype}
      </foreach>
  </select>

运行报错:Parameter 'listType' not found. Available parameters are [collection, list]

解决:1.通用方法,在dao层参数上加上@Param("listType"),所以养成加@Param是个好习惯

        2.将sql中Collection="listType"改为 Collection="list"或者"collection"

        3.对应方式处理二,如果参数是数组则这么改: Collection="array"

注意:也不是任何参数之前就加上@Param,实体类之前不需要加上注解@Param

   会报org.apache.ibatis.binding.BindingException: Parameter 'xx' not found

猜你喜欢

转载自www.cnblogs.com/caoxs/p/9229128.html