spring boot与mybatis-plus集成出现org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)
即 --> 绑定异常:无效的绑定语句(未找到)
—原因有几个方面:
1:xml文件里面的namespace对应的mapper接口路径是否正确。
<mapper namespace="com.dengqing.mapper.UserMapper">
2:Mapper接口里面的方法(findUserByUserId)是否对应xml里面的id=“findUserByUserId”,这里最好复制,不要全部手敲
3: 查看配置文件,自己配置的规则是否遵循
application.yml配置(application.properties同理,只是细节不一样):
mybatis-plus:
mapper-locations: classpath:com/dengqing/hahah/*.xml
type-aliases-package: com.dengqing.entity
pom.xml 配置:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!-- maven执行clean install或者install 出现问题:
Failed to execute goal org.apache.maven.plugins:maven-surefire- plugin:2.22.2:test (default-test)on project demo: There are test failures.
添加下列<plugin/> -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>true</skipTests>
</configuration>
</plugin>
</plugins>
<!--解决org.apache.ibatis.binding.BindingException: Invalid bound statement -->
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
</build>
我的定义的xml文件在/hahah包下面,但是接口在mapper包下面
如图
所以xml和持久层接口没有太强的关联关系,看你自己的配置而定,我的UserRoleMapper.xml和TUserMapper接口名称不相同、路径不相同一样可以调用。
原因3是重点,配置好了才能根据配置的规则使用,原因1、2是细节处理。**
如果有 spring boot与mybatis-plus(mybatis)集成问题的话,可以留言私我,后续的话我会将spring boot与mybatis-plus、shiro集成的上传到gitee。