org.apache.ibatis.binding.BindingException: Parameter 'idList' not found解决办法

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解决办法

原文地址:https://www.cnblogs.com/jing1617/p/10175225.html

时间: 2024-08-05 06:57:57

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

org.apache.ibatis.binding.BindingException: Parameter &#39;start&#39; not found. Available parameters are [1, 0, param1, param2]

DEBUG 2018-05-30 08:43:26,091 org.springframework.jdbc.datasource.DataSourceTransactionManager: Rolling back JDBC transaction on Connection [[email protected]]DEBUG 2018-05-30 08:43:26,091 org.mybatis.spring.SqlSessionUtils$SqlSessionSynchronization:

Spring Boot:Caused by: org.apache.ibatis.binding.BindingException: Parameter &#39;deptId&#39; not found.

1. 错误信息描述 在使用Spring Boot + Mybaits从前台向后台提交数据时,控制台报出该错误信息 2. 报错原因 在dao接口中,该方法拥有两个参数,Mybaits无法区分这两个参数 3. 解决方法 在dao方法中为这两个参数分别标注Mybaits的@Param注解,对这两个参数加以区分 List<ManagerSelectResult>selectToday(@Param("deptId") Integer deptId, @Param("off

【Mybatis异常】 org.apache.ibatis.binding.BindingException: Parameter &#39;storeId&#39; not found. Available parameters are [form, param1]

一.异常信息 2019-05-31 16:06:25.272 [http-nio-10650-exec-3] WARN o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver.logException(AbstractHandlerExceptionResolver.java:192) - Resolved exception caused by Handler execution: org.mybatis.spring.MyBatisSystemExce

org.apache.ibatis.binding.BindingException: Parameter &#39;xxx&#39; not found. Available parameters are [arg1, arg0, param1, param2]

这个异常说明参数没有加上@Param注解,加上这个注解就行了. org.apache.ibatis.binding.BindingException: Parameter 'xxx' not found. Available parameters are [arg1, arg0, param1, param2] 原文地址:https://www.cnblogs.com/FengZeng666/p/12012727.html

通过maven test 报org.apache.ibatis.binding.BindingException: Invalid bound statement

背景 直接使用eclipse工具去执行,没有问题,通过testng.xml去执行,没有问题,但通过mvn clean test执行,就报错,提示org.apache.ibatis.binding.BindingException: Invalid bound statement 解决方法 首先先肯定的是:mybatis的配置是没有问题,因为eclipse可以正常执行: 在eclipse中把mapper的xml文件放到src代码目录下是可以一起打包进classes的,而maven去编译的时候不会,

Exception:HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

主要错误信息如下: HTTP Status 500 - org.apache.ibatis.binding.BindingException: Invalid bound statement (not found) description The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.RuntimeException: org

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): da.huying.usermanage.mapper.UserMapper.queryUserById    at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:196)    at org.apache.ibatis.bindi

org.apache.ibatis.binding.BindingException

环境:spring3.1.1+mybatis3.2.8+mybatis-spring1.2.3 SpringMVC + MyBatis整合,出现下面的错误: org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (no

MyBatis笔记----报错:Exception in thread &quot;main&quot; org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)解决方法

报错 Exception in thread "main" org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.ij34.model.UserMapper.selectarticle at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:230) at or