项目场景:

最近跟着一些网上项目做了springboot的相关学习,真心觉得方便,快捷,好用,感觉自己学的差不多了,就想着自己完全独立做一个CRUD练练手,本想速战速决,没想到触发了一个隐秘的小坑,在这里备份一下,同大伙共勉

问题描述:

整个项目结构如下图所示,基本配置在application.yml中完成,sql语句放在resources文件夹下,方法的接口及实现在java包的service package里,实体类在po中,Dao文件放在mapper中,前端交互的方法放在controller里。

application.yml

server:port: 5678
spring:datasource:username: rootpassword:url: jdbc:mysql://localhost:3306/offcn?serverTimezone=GMT%2B8&useSSL=false&useUnicode=true&characterEncoding=UTF-8driver-class-name: com.mysql.cj.jdbc.Drivertype: com.alibaba.druid.pool.DruidDataSource#filters: stat  #开启监控过滤器
mybatis:#config-location: classpath:mybatis/mybatis-config.xmlmapper-locations: classpath:com/offcn/finalexam/mapper/*.xml
logging:file:path: D:\log\finalexam\level:com:offcn: debug  #日志的级别为调试   debug  info   error

StudentService

package com.offcn.finalexam.service;import com.offcn.finalexam.po.Student;import java.util.List;public interface StudentService {public String add(Student student);public String delete(int id);public String update(Student student);public Student find(int id);public List<Student> findAll();
}

StudentServiceImpl

package com.offcn.finalexam.service.impl;import com.offcn.finalexam.mapper.StudentMapper;
import com.offcn.finalexam.po.Student;
import com.offcn.finalexam.service.StudentService;
import org.springframework.stereotype.Service;import javax.annotation.Resource;
import java.util.List;@Service
public class StudetnServiceImpl implements StudentService {@Resourceprivate StudentMapper studentMapper;@Overridepublic String add(Student student) {studentMapper.insert(student);return "增加成功";}@Overridepublic String delete(int id) {studentMapper.deleteByPrimaryKey(id);return "删除成功";}@Overridepublic String update(Student student) {studentMapper.updateByPrimaryKey(student);return "更新成功";}@Overridepublic Student find(int id) {Student student = studentMapper.selectByPrimaryKey(id);return student;}@Overridepublic List<Student> findAll() {return studentMapper.selectByExample(null);}
}

StudentController

package com.offcn.finalexam.controller;import com.offcn.finalexam.po.Student;
import com.offcn.finalexam.service.StudentService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;import javax.annotation.Resource;
import java.util.List;@RestController
@RequestMapping("/student")
public class StudentController {@Resourceprivate StudentService studentService;@RequestMapping("/add")public String add(@RequestBody Student student) {return studentService.add(student);}@RequestMapping("/delete")public String delete(int id) {return studentService.delete(id);}@RequestMapping("/update")public String update(@RequestBody Student student) {return studentService.update(student);}@RequestMapping("/find")public Student find(int id) {return studentService.find(id);}@RequestMapping("/findAll")public List<Student> findAll() {return studentService.findAll();}
}

这些文件中java里的Dao/po,resources里的StudentMapper.xml,都是用代码生成器自动生成的(坑就出现在这里),检查整体结构和基本语法后没发现错误,就开心的运行了主程序,结果给我来了个白页,IDEA报错Invalid bound statement (not found)。


到网上查找相关信息,将问题锁定为项目运行时未找到mapper.xml文件,检查了application.yml的设置、主启动类的扫描设置,一个字母一个字母的对照,愣是没发现错误,直到后来看到一篇文章,那位仁兄说,他的resources下的文件夹为了避免出错是一级一级建的,我灵光一现,取消了压缩中间文件夹的设置,果然!resources里的文件夹没有展开!

这时我回想起来了,mapper.xml用代码生成器生成后,我是连带文件夹一并拷过来的,代码生成器里的文件夹层级设置可能有问题,而我又设置了压缩中间文件夹,导致这个错误在眼皮底下一直没被发现。
然后重建文件夹,将mapp.xml拖进去,重新启动,ok了。

总结:

1、开发阶段的压缩文件夹设置最好别打开,或者在检查阶段关闭这个设置,避免将正确文件夹层级和错误文件夹层级混淆;
2、如果项目运行时出现了扫描不到相关包的情况,需要检查包名、配置文件,还要检查一下包所在的目录结构;
3、从其他生成器或者项目中拷贝文件时,直接拷贝根文件,别为了省事连带文件夹一起拷贝,说不定就有什么坑埋在里边……

springboot整合mybatis之Invalid bound statement解决相关推荐

  1. SpringBoot整合mybatis时报Invalid bound statement (not found)错误的可能原因

    Invalid bound statement (not found)这个问题的实质就是mapper接口和mapper.xml没有映射起来 常见的低智商问题有下列几个 1.mapper.xml 里面的 ...

  2. springboot整合mybatis错误 Invalid bound statement (not found): com.yuan.mapper.UserMapper.getUserList

    出现的原因是 src文件下的mapper有mapper接口和映射文件,而target下的mapper文件却没有映射文件 =解决方案======== 1.把映射文件 放到resources 目录下 结构 ...

  3. springboot整合mybatis出现Invalid bound statement (not found): com.mapper.UserMapper.selectByPrimaryKey

    1.pom.xml中添加以下内容 <build>       <resources>         <resource>             <dire ...

  4. SpringBoot踩坑记录 Invalid bound statement (not found)引发的一些列问题

    SpringBoot踩坑记录 Invalid bound statement (not found)引发的一些列问题 当你开开心心搭建了一个SpringBoot项目,用插件生成了entity.dao. ...

  5. SpringBoot踩坑记录--Invalid bound statement (not found): com.zxq.crud.dao.UserDao.selectAllByDepart

    SpringBoot踩坑记录--Invalid bound statement: com.zxq.crud.dao.UserDao.selectAllByDepart 运行SpringBoot项目时提 ...

  6. Springboot项目中报错Invalid bound statement(not found):com.******报错处理

    报错: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.way.springb ...

  7. spring boot 集成Mybatis时 Invalid bound statement (not found)

    spring boot 集成Mybatis时,运行提示 org.apache.ibatis.binding.BindingException: Invalid bound statement (not ...

  8. MyBatis报Invalid bound statement (not found)错误

    一.场景 本项目使用mybatis-plus作为orm框架,使用的是以下jar包 compile 'com.baomidou:mybatis-plus-boot-starter:3.4.0' 都知道m ...

  9. MyBatis:Invalid bound statement (not found)

    Invalid bound statement (not found)Exception 这个异常的原因是:        由于程序在运行的时候会将mapper接口加载到target文件中,但是却没有 ...

最新文章

  1. java8的jvm优化_基于JDK8 版本的SpringBoot 启动参数优化(建议收藏)
  2. R语言使用vcd包的spine函数可视化spinogram图(spinogram图是被归一化的堆叠条形图、这样每个条形的高度一样、内部显示不同分布的比例)
  3. log4j用法http://zengjinliang.javaeye.com/blog/171550
  4. FD.io/VPP — QoS — DPDK Hqos
  5. language mysql_MySql 语言的分类;
  6. git查找两个分支的共同节点
  7. Jinja2模板引擎简介
  8. linux下文本模式不能登录,图形可以登录
  9. 北大cls_战报 | 第七届CLS“联合杯”篮球联赛
  10. DNS,NS,TTL相互关系
  11. MyScript基础功能
  12. 用初等解法解特定差分方程(韦达定理的应用)
  13. Apache Pegasus 首次 Meetup 圆满落幕
  14. java常用的编辑器之kindeditor
  15. matlab计算aqi代码,AQI计算第一课,爬取全部城市AQI数据的代码一样但是只能爬出第一个城市的数据是怎么回事?...
  16. 一种改版后检查硬件PCB生产资料的方法***-----Gerber对比,检查的方法
  17. 启动监听时的XDB、XPT和PLSExtProc服务的介绍
  18. win11使用win10右键菜单的方法
  19. 如何diy一款MATLAB进度条?
  20. 人体日常消耗千卡(大卡)或千焦

热门文章

  1. 互联网都在说降本增效,小红书技术团队是怎么做的?
  2. 七夕送什么礼物会让对方惊喜呢!2022最全情人节礼物指南
  3. 利用sentinel hub Python开发包查询和下载Sentinel-2等卫星遥感数据
  4. linux 搜狗输入法 太慢,【分享】ibus使用搜狗输入法词库后,反应慢的解决方法...
  5. 侍魂微信新服务器,侍魂手游2019年3月23日微信问答试炼答案
  6. Delphi 把字符串复制到剪贴板
  7. 三,c程序的编辑,编译,链接和运行
  8. Flutter AppBar设置渐变色背景
  9. 关注与粉丝表结构设计及查询
  10. 程序员用新华字典学英语