https://blog.csdn.net/qq_28379809/article/details/83342196

问题描述
使用Mybatis查询数据库报错:
org.apache.ibatis.binding.BindingException: Parameter 'idList' not found
1
接口是这样的:
public List<User> findByIdList(List<Integer> idList);
1
XML是这样的:
<select id="findByIdList" resultType="com.example.bean.User">
SELECT id, name, password, address, enable
FROM user
<where>
        <if test="idList != null and idList.size() > 0">
            id IN
            <foreach collection="idList" item="ietm" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
</where>
</select>
1
2
3
4
5
6
7
8
9
10
11
12
运行报错:org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.
原因分析
Mybatis传递参数是按位置传递的,也就是说下面一个接口:public User find(String name, String password), XML中使用参数是这样的select * from user where name = #{0} and password = #{1}.
如果想要按值传递,就得这样写:
// 接口
public User find(@Param("name")String name, @Param("password")String password)
<!-- xml -->
select * from user where name = #{name} and password = #{password}
1
2
3
4
5
这样一看是不是明白了?Mybatis是按顺序传递参数的。
想要在xml中通过参数的name获取,就得加上@Param("")注解,不然就只能使用Mybatis默认的写法。
解决办法
解决办法有两种:
Mybatis默认写法——list
第一种写法是使用Myabtis默认的写法, 在xml中用list接收参数,如下:
// 接口
public List<User> findByIdList(List<Integer> idList);
<select id="findByIdList" resultType="com.example.bean.User">
SELECT id, name, password, address, enable
FROM user
<where>
        <if test="list!= null and list.size() > 0">
            id IN
            <foreach collection="list" item="ietm" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
</where>
</select>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
使用注解
第二种方式就是使用@Param("")注解,如下:
// 接口
public List<User> findByIdList(@Param("idList")List<Integer> idList);
<select id="findByIdList" resultType="com.example.bean.User">
SELECT id, name, password, address, enable
FROM user
<where>
        <if test="idList!= null and idList.size() > 0">
            id IN
            <foreach collection="idList" item="ietm" index="index" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
</where>
</select>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Mybatis默认参数传递方式
Mybatis关于各种类型的单参数默认的写法如下:
类型 接收参数方式
基本数据类型 顺序,如#{0},也可以用name直接获取,如#{name}
List list
数组 array
Map 根据key获取map中各参数即可,如#{key}
自定义的对象 根据get方法对应的参数,使用name获取即可,如#{name}
如果是多参数,比如public User find(String address, List<Integer> idList), 使用注解@Param("")或者考虑封装在map中传递。
--------------------- 
作者:eknows 
来源:CSDN 
原文:https://blog.csdn.net/qq_28379809/article/details/83342196 
版权声明:本文为博主原创文章,转载请附上博文链接!

org.apache.ibatis.binding.BindingException: Parameter 'idList' not found解决办法的更多相关文章

  1. MyBatis 传List参数 nested exception is org.apache.ibatis.binding.BindingException: Parameter 'idList' not found.

    在MyBatis传入List参数时,MyBatis报错:nested exception is org.apache.ibatis.binding.BindingException: Paramete ...

  2. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'username' not found. Available parameters are [1, 0, param1, param2]

    Spring+mybatis错误:org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.bi ...

  3. ### Cause: org.apache.ibatis.binding.BindingException: Parameter 'name' not found. Available parameters are [arg1, arg0, param1, param2]

    org.apache.ibatis.exceptions.PersistenceException: ### Error updating database. Cause: org.apache.ib ...

  4. 怪事年年有,今天特别多!org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'empno' not found. Available parameters are [emp, deptno, param1, param

    错误: org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.Binding ...

  5. org.apache.ibatis.binding.BindingException: Parameter 'start' not found. Available parameters are [1, 0, param1, param2]

    DEBUG 2018-05-30 08:43:26,091 org.springframework.jdbc.datasource.DataSourceTransactionManager: Roll ...

  6. Springboot-001-解决nested exception is org.apache.ibatis.binding.BindingException: Parameter 'env' not found. Available parameters are [arg1, arg0, param1, param2]

    环境:Springboot + Mybatis + MySQL + VUE 场景: 前端发出数据比对请求,在服务后台与数据库交互时,接口提示错误信息如下所示: { "code": ...

  7. SpringBoot整合Mybatis注解版---update出现org.apache.ibatis.binding.BindingException: Parameter 'XXX' not found. Available parameters are [arg1, arg0, param1, param2]

    SpringBoot整合Mybatis注解版---update时出现的问题 问题描述: 1.sql建表语句 DROP TABLE IF EXISTS `department`; CREATE TABL ...

  8. Caused by: org.apache.ibatis.binding.BindingException: Parameter 'parameter' not found.解决

    Caused by: org.apache.ibatis.binding.BindingException: Parameter 'company' not found. Available para ...

  9. org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.binding.BindingException: Parameter 'userId' not found. Available parameters are [arg1, arg0, param1, param2]

    2018-06-27 16:43:45.552  INFO 16932 --- [nio-8081-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : ...

随机推荐

  1. 06 面向对象:多态&抽象类&接口&权限修饰符&内部类

    多态: /* 多态(polymorphic)概述 * 事物存在的多种形态 多态前提 * a:要有继承关系. * b:要有方法重写. * c:要有父类引用指向子类对象. * 成员变量 * 编译看左边(父 ...

  2. hdu3746 Cyclic Nacklace KMP

    CC always becomes very depressed at the end of this month, he has checked his credit card yesterday, ...

  3. Caused by: java.sql.SQLException: ORA-24816: 在实际的 LONG 或 LOB 列之后提供了扩展的非 LONG 绑定数据

    今天客户说报告草稿保存不了,跟踪错误bug,了解到以下reason: 异常出现的环境:oracle11g + Hibernate 错误分析:这是oracle 11g在clob字段中的一个bug,ora ...

  4. BootStrap------之模态框1

    <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="utf-8& ...

  5. Go Example--指针

    package main import ( "fmt" ) func zeroval(ival int) { ival = 0 } func zeroptr(iptr *int) ...

  6. python使用dns轮循检测web服务器是否异常

    我使用的是python2.7,我本来另装了一个python3.6,发现无法安装dnspython,于是只能换回来了 import dns.resolver #这个需要另外下载并安装(下载地址www.d ...

  7. 01python简介

    目录 1.  Python起源 2.  解释器 3.  Python 的设计目标 4.  Python 的设计哲学 5.  为什么选择  Python ? 6.  Python 特点 7.  Pyth ...

  8. Javascript高级调试——console.table()

    原文:http://www.mariusschulz.com/2013/11/13/advanced-javascript-debugging-with-consoletable 本文只是简单翻译,部 ...

  9. MCU ADC 进入 PD 模式后出现错误的值?

    MCU ADC 进入 PD 模式后出现错误的值? 在调试一款 MCU,最开始问题是无法读到 ADC 的值,应该是读到的值是异常高. 怀疑问题 可能是主频太低,为了降低功耗,这个 MCU 主频被我降了很 ...

  10. ML(附录2)——最小二乘法

    参见  :多变量微积分笔记2——最小二乘法