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. 01 mysql

    Sql语句: Structured Query Language, 结构化查询语言 分类: DDL (数据定义语句) 数据定义语言 - Data Definition Language 用来定义数据库 ...

  2. AtCoder Grand Contest 031 简要题解

    AtCoder Grand Contest 031 Atcoder A - Colorful Subsequence description 求\(s\)中本质不同子序列的个数模\(10^9+7\). ...

  3. Redis怎么保持缓存与数据库一致性?

    将不一致分为三种情况: 1. 数据库有数据,缓存没有数据: 2. 数据库有数据,缓存也有数据,数据不相等: 3. 数据库没有数据,缓存有数据. 在讨论这三种情况之前,先说明一下我使用缓存的策略,也是大 ...

  4. 浮动IP(Floating IPs):开始构建你的高可用性的应用

    高可用性是所有生产环境的关键.开发者因此可以高枕无忧因为他们知道他们的应用被设计为可以承受住故障. 今天,我们非常激动的宣布我们应用了浮动IP技术.浮动IP指的是一个IP地址可以立即从一个Drople ...

  5. xenserver开启虚拟机时提示找不到存储介质,强制关闭和重启都没用

    具体报错内容为: this vm needs storage that cannot be seen from that host 该错误的原因是该虚拟机使用了外部存储介质,例如,我就是因为当初规划x ...

  6. jenkins 集成 keycloak 认证

    keycloak 是很不错的sso 工具,当然也有Jenkins 的插件,我们可以使用jenkins 插件,方便用户账户的管理 环境准别 docker-compose version: "3 ...

  7. Java Bitset

    Bitset创建一种特殊的数组来保存非负整数的值 取值为true和false,初始都是false.Bitset初始化是一个long,65位,增加位数的话只能是64的整数倍. 如果用一个Bitset存储 ...

  8. trac

    F:\Python27>python F:\portabletrac\ez_setup.pyDownloading https://pypi.io/packages/source/s/setup ...

  9. input 修改placeholder颜色

    一般来说input的placeholder是不能修改的,但是现在浏览器利用伪类实现了对placeholder的修改 input::-webkit-input-placeholder { // cher ...

  10. taro 最佳实践

    对 JSX 支持程度补充说明: 不能在包含 JSX 元素的 map 循环中使用 if 表达式 不能使用 Array#map 之外的方法操作 JSX 数组 不能在 JSX 参数中使用匿名函数 暂不支持在 ...