MybatisPlus报错Invalid bound statement (not found)的解决方案
今天使用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)的解决方案的更多相关文章
- 解决Mybatis 报错Invalid bound statement (not found)
解决Mybatis 报错Invalid bound statement (not found) 出现此错误的原因 1.xml文件不存在 2.xml文件和mapper没有映射上 namespace指定映 ...
- springboot+mybatis报错Invalid bound statement (not found)
今天做项目时报了一个错提示说Invalid bound statement (not found),也就是说mapper接口绑定.xml文件出错了,找不到指定的sql:原因是程序没有把.xml文件编译 ...
- IDEA maven项目下测试mybatis例子,使用mappper class或package引入mapper映射文件,总是报错Invalid bound statement(所有配置完全正确)
困扰几个小时,终于查到解决办法及原因(可以直接到最后看解决方案) 环境就是用IDEA搭建的maven项目,主要jar包引入配置如下 <dependencies> <dependenc ...
- Mybatis plus 报错Invalid bound statement (not found) 终极解决办法
我产生的错误原因是写的mapper继承BaseMapper没有添加泛型: 点进去: 为了解决这个bug,网上很多人也提出了解决办法:1.检查xml文件的namespace是否正确 2.Mapper.j ...
- 使用Mybatis时报错Invalid bound statement (not found):
使用逆向工程时生成的.xml文件在conf目录下,而使用查询方法时,无法在dao包下找到xml文件,所以报错. 测试代码如下所示: @Test public void testSimple() thr ...
- 关于Maven整合SSM项目中报错Invalid bound statement (not found):的问题解决
如图:控制不报错 页面就是报500的错误 查阅了好多资料 都说是Mapper文件写的不对 我仔细找了好几遍也解决不了问题.. 解决: 坑爹的问题害我找了一上午原因,原来是需要在pom.xml文件中 ...
- MyBatis切换至MyBatis-plus踩坑Invalid bound statement (not found):
部分情况可以参考https://blog.csdn.net/wwrzyy/article/details/86034458 我的问题出现的根本原因就是没有扫描到mapper的xml文件 因为MyBat ...
- Invalid bound statement (not found): com.xxxx.dao.other.LoginDao.getUser"
原来是能正常运行的,后想把登录相关的调整一下目录,对应登录的文件都调整到了other下边,启动服务,请求时报错: Invalid bound statement (not found): com.xx ...
- oracle+mybatis报错:BindingException("Invalid bound statement (not found): ")
oracle+mybatis报错:BindingException("Invalid bound statement (not found): ") 从mysql转到oracle数 ...
随机推荐
- Python利用切片操作,实现一个trim()函数,去除字符串首尾的空格,注意不要调用str的strip()方法:
这是一个最简单的自定义函数,自己调用自己,我的理解是这样的: 1.传一个s参数进行判断,如果有空字符它会切掉前后的空字符,返回一个新的s,这个新的s还有的话会继续执行这种重复的操作,类似于递归(博主不 ...
- 细数 SharedPreferences 的那些槽点 !
前言 最近在处理一个历史遗留项目的时候饱受其害,主要表现为偶发性的 SharedPreferences 配置文件数据错乱,甚至丢失.经过排查发现是多进程的问题.项目中有两个不同进程,且会频繁的读写 S ...
- Nginx总结(五)如何配置nginx和tomcat实现反向代理
前面讲了如何配置Nginx虚拟主机,大家可以去这里看看nginx系列文章:https://www.cnblogs.com/zhangweizhong/category/1529997.html 今天要 ...
- 从零开始开发IM(即时通讯)服务端
好消息:IM1.0.0版本已经上线啦,支持特性: 私聊发送文本/文件 已发送/已送达/已读回执 支持使用ldap登录 支持接入外部的登录认证系统 提供客户端jar包,方便客户端开发 github链接: ...
- PHP文件基础操作
文件的基本操作:(更多) fopen():文件打开 $file = fopen("file.txt","r+"); fopen()函数的参数是目标文件的路径和文 ...
- Keras(六)Autoencoder 自编码 原理及实例 Save&reload 模型的保存和提取
Autoencoder 自编码 压缩与解压 原来有时神经网络要接受大量的输入信息, 比如输入信息是高清图片时, 输入信息量可能达到上千万, 让神经网络直接从上千万个信息源中学习是一件很吃力的工作. 所 ...
- SCRUM的四大支柱
转自:http://www.scrumcn.com/agile/scrum-knowledge-library/scrum.html#tab-id-9 迭代开发 在Scrum的开发模式下,我们将开发周 ...
- 牛客小白赛4 A 三角形 数学
链接:https://www.nowcoder.com/acm/contest/134/A来源:牛客网 题目描述 铁子从森林里收集了n根木棍,她开始将它们按顺序的排成一排,从左到右依次为1到n,她回想 ...
- codeforces 814 D. An overnight dance in discotheque (贪心+bfs)
题目链接:http://codeforces.com/contest/814/problem/D 题意:给出奇数个舞者,每个舞者都有中心坐标和行动半径,而且这些点组成的园要么相互包含要么没有交集求,讲 ...
- HDU5461 Largest Point 思维 2015沈阳icpc
Largest Point Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...