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. 2018.4.23 git命令总结

    git clone git pull git add xx git add . git add -A git branch 查看本地分支 git branch --all 查看所有分支 git bra ...

  2. Kubernetes学习

    DNS for Services and Pods Services 创建基本的Service kind: Service spec.clusterIP: 为一组相同的服务的Pod集群提供一个虚拟ip ...

  3. hdu1846 Brave Game 博弈

    十年前读大学的时候,中国每年都要从国外引进一些电影大片,其中有一部电影就叫<勇敢者的游戏>(英文名称:Zathura),一直到现在,我依然对于电影中的部分电脑特技印象深刻.今天,大家选择上 ...

  4. git使用之放弃本地修改

    一,未使用 git add 缓存代码时. 可以使用 git checkout  --  filepathname (比如: git checkout -- readme.md ,不要忘记中间的 “-- ...

  5. python实现单链表的翻转

    #!/usr/bin/env python #coding = utf-8 class Node:     def __init__(self,data=None,next = None):      ...

  6. REPL

    REPL(Read Eval Print Loop:交互式解释器) 表示一个电脑的环境,类似 Window 系统的终端或 Unix/Linux shell,我们可以在终端中输入命令,并接收系统的响应. ...

  7. 时间标准基础知识UTC和ISO8601

    过去世界各地原本各自订定当地时间,但随着交通和电讯的发达,各地交流日益频繁,不同的地方时间,造成许多困扰,于是在西元1884年的国际会议上制定了全球性的标准时,明定以英国伦敦格林威治这个地方为零度经线 ...

  8. celery + redis quick start

    软件: redis server redis-server.exe 安装redis for python using pip 安装celery (redis)  pip install -U &quo ...

  9. node nightmare 网页自动化测试 sample

    安装nightmare 编写1.js 运行 node 1.js var Nightmare = require('nightmare');var nightmare = Nightmare({ sho ...

  10. 决策树原理实例(python代码实现)

    决策数(Decision Tree)在机器学习中也是比较常见的一种算法,属于监督学习中的一种.看字面意思应该也比较容易理解,相比其他算法比如支持向量机(SVM)或神经网络,似乎决策树感觉“亲切”许多. ...