springboot mybatis mysql8.0 异常 invalid bound statement (not found)(汇总篇)

大家好,我是烤鸭:

    现在是采坑实录。

    invalid bound statement (not found)  这个坑用过mybatis的人肯定都踩过。

1. 环境

    <parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.0.RELEASE</version>
	</parent>
    <dependencies>
        <dependency>
			<groupId>org.mybatis</groupId>
			<artifactId>mybatis</artifactId>
			<version>3.4.6</version>
		</dependency>
		<dependency>
			<groupId>mysql</groupId>
			<artifactId>mysql-connector-java</artifactId>
			<version>8.0.12</version>
		</dependency>
        <dependency>
			<groupId>com.alibaba</groupId>
			<artifactId>druid</artifactId>
			<version>1.1.10</version>
		</dependency>
    </dependencies>

druid 1.1.10

mysql 8.0

springboot 2.0

mybatis 3.4.6

解决方案:

看这篇(比较常规,方法找不到或者xml映射错误)

https://www.cnblogs.com/liaojie970/p/8034525.html

如果解决不了,看这篇:(pom.xml文件中配置resource)

https://blog.csdn.net/k469785635/article/details/77532512

还解决不了,看这篇(有关mysql 8.0的连接错误):

https://blog.csdn.net/qq_20788055/article/details/80380099

我的就是还解决不了。看这篇(mapper-locations的路径配置)

https://blog.csdn.net/loco_1/article/details/79711839

解决了。

问题重现:

  mybatis:
  mapper-locations: classpath:com.mys.my.app.mapper/*.xml
  type-aliases-package: com.mys.my.app.pojo

改为:

  mybatis:
  mapper-locations: classpath*:com/mys/my/app/mapper/*.xml
  type-aliases-package: com.mys.my.app.pojo

出这种问题找半天,真是想骂自己啊。

ps:

在idea中对 mapper 文件夹 重命名(快捷键alt+shift+r) ,类似上面

如果是 com.mys.my.app.mapper (可能作为包结构或者文件夹名称就叫com.mys.my.app.mapper),

mapper-locations: classpath:com.mys.my.app.mapper/*.xml

如果是mapper(说明是文件夹层级,末级文件夹是mapper)

mapper-locations: classpath:com/mys/my/app/mapper/*.xml

猜你喜欢

转载自blog.csdn.net/Angry_Mills/article/details/81535888
今日推荐