org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.da

IDEA中整合Springboot+SpringMVC+Mybatis报错:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.dao.UserMapper.insertUserInfo
    at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:235) ~[mybatis-3.5.5.jar:3.5.5]
    at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:53) ~[mybatis-3.5.5.jar:3.5.5]
    at org.apache.ibatis.binding.MapperProxy.lambda$cachedInvoker$0(MapperProxy.java:115) ~[mybatis-3.5.5.jar:3.5.5]
    at java.util.concurrent.ConcurrentHashMap.computeIfAbsent(ConcurrentHashMap.java:1660) ~[na:1.8.0_144]
    at org.apache.ibatis.binding.MapperProxy.cachedInvoker(MapperProxy.java:102) ~[mybatis-3.5.5.jar:3.5.5]
    at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:85) ~[mybatis-3.5.5.jar:3.5.5]
    at com.sun.proxy.$Proxy56.insertUserInfo(Unknown Source) ~[na:na]
    at com.example.demo.service.UserService.AddUserInfo(UserService.java:20) ~[classes/:na]
    at com.example.demo.controller.UserController.AddUserInfo(UserController.java:19) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_144]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_144]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_144]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_144]

解决方法:

   下面是一个简单的项目结构:

Mapper接口的全类名是:com.example.demo.dao

Mapper.xml配置文件的路径是:resources.mappers

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.da_第1张图片

1.mapper.xml的namespace是mapper接口文件的全类名

2.mapper.xml和mapper接口文件中的方法名称要一致

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.da_第2张图片

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.da_第3张图片

3.Springboot的配置文件中application.yml

4.项目名+Application.java文件中

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.example.demo.da_第4张图片 

但是!

有些时候,在上面的都填写正确后,还是会报那个错误,原因在于和mapper接口文件相互绑定的 .xml文件不是代码,无需编译,但是需要指定在编译时将指定的资源文件(此处为 .xml文件拷贝到对应目录下(此处应当为 编译好之后 类文件的对应目录

需要在pom.xml文件中配置resources,来指定mapper.xml所在的位置,不然mapper.xml文件就会被漏掉!

5.pom.xml文件中配置resources


	
		
			org.springframework.boot
			spring-boot-maven-plugin
		
	
	
		
			src/main/
			
			
				**/*.xml
			
		
		
		
			src/main/resources
		
	

 

你可能感兴趣的:(Springboot,Web后台,java,mybatis,xml)