org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found.的问题解决办法

简介: org.apache.ibatis.binding.BindingException: Parameter 'XXXX' not found.的问题解决办法

前言:出现这个问题的原因有好几个,所以我们逐步的来解释并解决问题;
1、首先,要明确一点的是,Dao层的抽象方法中的参数一般情况下默认的是一个参数或者一个对象;
例如:

public interface StudentDao {

int selectById(int id);

int insert(Student stu);
}

这两种是正常的方式,不会出现什么问题,mappper中的对应取值都是用#{}这种方式;
例如:

select

from student
where 1=1 and id = #{id}


insert into inbox_template (name,age)
values (#{name},#{age})

上面如果是student对象作为参数,那么mapper中不能少了parameterType,否则会找不对应的属性
2、当传多个参数时,就容易出现问题了,问题重现,如果像下面那样写就会出现标题中的错误,找不到参数;

public interface StudentDao {
int selectBySelective(int id,String name);

}

解决办法就是在每个参数前加上@param注解,括号中注解的名称就是mapper中映射的值,如下:

import org.apache.ibatis.annotations.Param;

public interface StudentDao {

int selectBySelective(@Param("id")int id,@Param("name")String name);

}

mapper中还是那样写,可以使用${}或者#{}任意一种方式:

select

from student
where name = #{pname} and id = #{pid}

3、既有参数又有对象时,对象也需要注解,一般参数的直接取,对象的需要对象.属性,如下:

public interface StudentDao {

int selectBySelective(@Param("page")int page,@Param("stu")Student stu);

}

mapper:



select

from student
where name = #{stu.name} and id = #{stu.id} limit 0 ,#{page}
目录
相关文章
|
1月前
|
Java 数据库连接 mybatis
解决Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found
解决Error querying database. Cause: org.apache.ibatis.executor.ExecutorException: No constructor found
143 1
|
22天前
|
XML Java 数据库连接
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):XXXXX
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found):XXXXX
|
1月前
|
XML Java 数据库连接
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.forum.d
26 1
|
15天前
|
Java 数据库连接 mybatis
【已解决】nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘qcBizname‘ not found
【已解决】nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘qcBizname‘ not found
21 0
|
1月前
|
前端开发 Java 数据库连接
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
若依 mybatis报错nested exception is org.apache.ibatis.binding.BindingException: Parameter ‘XXX‘ 错误
32 0
|
1月前
|
前端开发 应用服务中间件 网络安全
在Apache上http强制跳转到https无效的解决办法
在Apache上http强制跳转到https无效的解决办法
113 0
|
8月前
|
XML Java 数据库连接
MyBatis参数映射问题解决教程: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 wit
MyBatis参数映射问题解决教程: org.apache.ibatis.type.TypeException: Error setting non null for parameter #1 wit
509 1
|
7月前
org.apache.ibatis.builder.BuilderException: An invalid property ‘jdbcType ‘ was found in mapping
org.apache.ibatis.builder.BuilderException: An invalid property ‘jdbcType ‘ was found in mapping
|
7月前
|
Apache Windows
Apache No installed service named “Apache2.4“的解决办法
Apache No installed service named “Apache2.4“的解决办法
123 0
|
8月前
|
XML Java 数据库连接
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
【异常解决】解决org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)问题
125 0

推荐镜像

更多