1.org.apache.ibatis.binding.BindingException: Invalid bound statement报错处理#

使用springboot集成mybatis,在接口和映射文件都写好后执行查询报错。

接口文件

1
2
3
4
5
6
7
8
9
10
11
package com.qhc.springboot2.dao;

import com.qhc.springboot2.beans.User;

import java.util.List;

public interface UserDao {
User queryById(int id);

List<User> getAll();
}

mybatis映射文件UserMapping.xml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="com.qhc.springboot2.dao">

<resultMap id="BaseResultMap" type="com.qhc.springboot2.beans.User">
<result column="id" jdbcType="INTEGER" property="id" />
<result column="userName" jdbcType="VARCHAR" property="userName" />
<result column="passWord" jdbcType="VARCHAR" property="passWord" />
<result column="realName" jdbcType="VARCHAR" property="realName" />
</resultMap>

<select id="queryById" resultMap="BaseResultMap">
select * from user where id = #{id}
</select>

<select id="getAll" resultMap="BaseResultMap">
select * from user
</select>

</mapper>

注意:我上面写的namespace是<mapper namespace="com.qhc.springboot2.dao">这写法不能对应到指定的接口文件,就会报错:

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

修改方法

将映射文件中namespace修改为com.qhc.springboot2.dao.UserDao问题即可解决。