今天使用MybatisPlus,测试时报错Invalid bound statement (not found)

使用自定义的mapper接口中的方法可以执行,而调用MybatisPlus中baseMapper中的方法会报错

因此可以排除是路径配置问题

查询网上各种解决方案依旧无果之后,从头到尾梳理了一下代码,找到了错误

package com.jt.pojo;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import lombok.experimental.Accessors;
import org.springframework.stereotype.Component; import java.io.Serializable; //基于ORM思想,属性与表一致
@Data
@Accessors(chain=true)
@TableName//如果表明与类名一致可以省略
public class User implements Serializable {
//自动生成序列化编号,settings-editor-inspections-serializable without serialVersionUID
private static final long serialVersionUID = -7155610581355123677L;
//标识主键,并且主键自增
@TableId(type= IdType.AUTO)
//如果字段属性名称一致,可以省略配置
private Integer id;
//@TableField(value = "name")
private String name;
private Integer age;
private String sex;
}
package com.jt.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.jt.pojo.User;
import org.apache.ibatis.annotations.Mapper;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.stereotype.Component; import java.util.List; //代理方式:1.JDK代理(默认配置)2.CGLIB代理
//如果被代理者是接口,默认采用JDK代理.规定:jdk代理,必须有接口
//如果被代理者没有接口(没有实现接口)默认采用CGLIB.规定:可以创建任何对象的代理,代理者是目标对象的子类
//@Mapper//将接口交给spring管理,接口并不能创建duixiang,管理的是UserMapper的代理对象
//@MapperScan("com.jt.mapper")将此注解添加到启动类,可以自动扫描mapper包下的所有注解,因此此处不用再添加@mapper
public interface UserMapper extends BaseMapper {
List<User> findAll();
}
package com.jt.springbootmybatis;

import org.mybatis.spring.annotation.MapperScan;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ImportResource; @SpringBootApplication
@MapperScan("com.jt.mapper")
public class SpringbootMybatisApplication {
@Bean
public MapperScannerConfigurer mapperScannerConfigurer(){
MapperScannerConfigurer scannerConfigurer = new MapperScannerConfigurer();
//可以通过环境变量获取你的mapper路径,这样mapper扫描可以通过配置文件配置了
scannerConfigurer.setBasePackage("com.yourpackage.*.mapper");
return scannerConfigurer;
} public static void main(String[] args) {
SpringApplication.run(SpringbootMybatisApplication.class,args);
}
}
package com.jt.springbootmybatis;

import com.jt.mapper.UserMapper;
import com.jt.pojo.User;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner; import java.util.List; @RunWith(SpringRunner.class)
@SpringBootTest
public class SpringbootMybatisApplicationTests {
@Autowired
private UserMapper userMapper; @Test
public void testFindAll() {
List<User> list = userMapper.selectList(null);
System.out.println(list);
} }

启动测试类调用selectList方法报错,而调用findAll方法运行正常

解决方案:pojo的UserMapper中,通过@TableName与表名进行了关联,所以在继承BaseMapper接口时,要指定BaseMapper<User>的泛型

完美解决

MybatisPlus报错Invalid bound statement (not found)的解决方案的更多相关文章

  1. 解决Mybatis 报错Invalid bound statement (not found)

    解决Mybatis 报错Invalid bound statement (not found) 出现此错误的原因 1.xml文件不存在 2.xml文件和mapper没有映射上 namespace指定映 ...

  2. springboot+mybatis报错Invalid bound statement (not found)

    今天做项目时报了一个错提示说Invalid bound statement (not found),也就是说mapper接口绑定.xml文件出错了,找不到指定的sql:原因是程序没有把.xml文件编译 ...

  3. IDEA maven项目下测试mybatis例子,使用mappper class或package引入mapper映射文件,总是报错Invalid bound statement(所有配置完全正确)

    困扰几个小时,终于查到解决办法及原因(可以直接到最后看解决方案) 环境就是用IDEA搭建的maven项目,主要jar包引入配置如下 <dependencies> <dependenc ...

  4. Mybatis plus 报错Invalid bound statement (not found) 终极解决办法

    我产生的错误原因是写的mapper继承BaseMapper没有添加泛型: 点进去: 为了解决这个bug,网上很多人也提出了解决办法:1.检查xml文件的namespace是否正确 2.Mapper.j ...

  5. 使用Mybatis时报错Invalid bound statement (not found):

    使用逆向工程时生成的.xml文件在conf目录下,而使用查询方法时,无法在dao包下找到xml文件,所以报错. 测试代码如下所示: @Test public void testSimple() thr ...

  6. 关于Maven整合SSM项目中报错Invalid bound statement (not found):的问题解决

    如图:控制不报错 页面就是报500的错误 查阅了好多资料  都说是Mapper文件写的不对  我仔细找了好几遍也解决不了问题.. 解决: 坑爹的问题害我找了一上午原因,原来是需要在pom.xml文件中 ...

  7. MyBatis切换至MyBatis-plus踩坑Invalid bound statement (not found):

    部分情况可以参考https://blog.csdn.net/wwrzyy/article/details/86034458 我的问题出现的根本原因就是没有扫描到mapper的xml文件 因为MyBat ...

  8. Invalid bound statement (not found): com.xxxx.dao.other.LoginDao.getUser"

    原来是能正常运行的,后想把登录相关的调整一下目录,对应登录的文件都调整到了other下边,启动服务,请求时报错: Invalid bound statement (not found): com.xx ...

  9. oracle+mybatis报错:BindingException("Invalid bound statement (not found): ")

    oracle+mybatis报错:BindingException("Invalid bound statement (not found): ") 从mysql转到oracle数 ...

随机推荐

  1. Flutter学习笔记(23)--多个子元素的布局Widget(Rwo、Column、Stack、IndexedStack、Table、Wrap)

    如需转载,请注明出处:Flutter学习笔记(23)--多个子元素的布局Widget(Rwo.Column.Stack.IndexedStack.Table.Wrap) 上一篇梳理了拥有单个子元素布局 ...

  2. 图表控件业界革命 -Arction新产品LightningChart JS 上市

    芬兰高科技企业Arction Ltd 在今年8月份推出了用于网页的数据可视化控件新解决方案—— LightningChart JS. 初次的基准测试表明,该产品为网页应用程序的数据可视化刷新了新的纪录 ...

  3. Spring学习之旅(十二)--持久化框架

    对于本职工作来说 JDBC 就可以很好的完成,但是当我们对持久化的需求变得更复杂时,如: 延迟加载 预先抓取 级联 JDBC 就不能满足了,我们需要使用 ORM框架 来实现这些需求. Spring 对 ...

  4. 蓝桥杯单片机CT107D 01 底层驱动基础

    代码下载 https://share.weiyun.com/5NHvLxG 这两个代码文件是其他底层驱动代码的基础: 包含了控制138573(间接控制数码管led和蜂鸣器等).delay延时函数.CT ...

  5. TypeScript进阶开发——ThreeJs基础实例,从入坑到入门

    前言 我们前面使用的是自己编写的ts,以及自己手动引入的jquery,由于第三方库采用的是直接引入js,没有d.ts声明文件,开发起来很累,所以一般情况下我们使用npm引入第三方的库,本文记录使用np ...

  6. [python]错误检测及异常处理try-except

    1. 简介 要给代码添加错误检测及异常处理,只需要将其封装在try-except中. try:通常的代码 except:处理错误和异常的代码 2. 示例 import os try: path = ' ...

  7. CodeForces 785 D Anton and School - 2 范德蒙恒等式

    Anton and School - 2 题解: 枚举每个左括号作为必选的. 那么方案数就应该是下面的 1 , 然后不断化简, 通过范德蒙恒等式 , 可以将其化为一个组合数. 代码: #include ...

  8. CF1027C Minimum Value Rectangle 贪心 数学

    Minimum Value Rectangle time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. codeforces 454 E. Little Pony and Summer Sun Celebration(构造+思维)

    题目链接:http://codeforces.com/contest/454/problem/E 题意:给出n个点和m条边,要求每一个点要走指定的奇数次或者是偶数次. 构造出一种走法. 题解:可能一开 ...

  10. Windows下安装youtube-dl(下载各大网站视频)

    youtube-dl干什么用的? 惯例,看官方介绍: youtube-dl is a command-line program to download videos from YouTube.com ...