三步教你解决Invalid bound statement (not found): com.xxx.dao.xxxDao.selectByxx错误!!!!很简单

不废话

直接来啊

1 问题实质: dao层(又叫mapper接口)跟mapper.xml文件没有映射

2 问题原因: 出现这种映射问题的原因分为低级原因和更低级原因两种

                     更低级原因:

                                              (1)dao层的方法和mapper.xml中的方法不一样;

                                              (2)mapper中的namespace resultParameter 和对应的dao层entity层不一样

                                              (3)拼写错误 如漏写 少写 多写....

                                              上述这些原因都会导致两者不能映射 这些检查和修正的工作自己来吧不会的百度就行

                  低级原因: spring配置文件中关于mybatis的与xml文件路径寻找相关的配置没有写

                                    导致调用dao层方法时,没有寻找dao.xml文件的正确路径 结果dao迷路了 从而两者无法映射

3 解决思路: 把dao.xml(或mapper.xml)路径配置写好!!!!

                     既然出发点(dao)已经确定,目的地(dao.xml/mapper.xml)也确定了

                     想到到达就必须画一条到dao.xml的路

4 解决步骤:

                   (1)打开spring-context.xml配置文件

                   (2)找到class为org.mybatis.spring.SqlSessionFactoryBean 这个bean

                   (3)找到name为mapperLocations的property

                   (4)在list标签中添加一个value

                                     例如:

                                             <value>classpath:/info/mappings/**/*.xml</value>

                  重启,问题解决!!!

                 注:classpath是配置好的类路径 要想知道表示什么 最简单的方式是参考其他list看一眼比对项目结构就了然了

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found)

01-07

问题如下:rn[org.springframework.web.servlet.mvc.support.DefaultHandlerExceptionResolver] - Resolving exception from handler [public java.lang.String com.cn.hnust.controller.UserController.toIndex(java.lang.String,java.lang.String,org.springframework.ui.Model)]: org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.cn.hnust.dao.UserMapper.insertSelectivern[org.springframework.web.servlet.DispatcherServlet] - Could not complete requestrnorg.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.cn.hnust.dao.UserMapper.insertSelectivern at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:189)rn at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:43)rn at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:58)rn at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:51)rn at com.sun.proxy.$Proxy16.insertSelective(Unknown Source)rn at com.cn.hnust.service.impl.UserServiceImpl.insertUser(UserServiceImpl.java:25)rn at com.cn.hnust.controller.UserController.toIndex(UserController.java:34)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)rn at java.lang.reflect.Method.invoke(Method.java:497)rn at org.springframework.web.method.support.InvocableHandlerMethod.invoke(InvocableHandlerMethod.java:215)rn at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:132)rn at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:104)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:749)rn at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:690)rn at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:83)rn at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:945)rn at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:876)rn at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:961)rn at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:863)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:650)rn at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:837)rn at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.springframework.web.filter.HiddenHttpMethodFilter.doFilterInternal(HiddenHttpMethodFilter.java:77)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)rn at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:108)rn at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)rn at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)rn at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)rn at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)rn at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)rn at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)rn at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)rn at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)rn at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)rn at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)rn at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)rn at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)rn at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)rn at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)rn at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)rn at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)rn at java.lang.Thread.run(Thread.java:745)rn__________________________________________________________________________________________________rnrn利用mybatis-generator-core-1.3.2自动生成UserMapper,UserMapper.xml,User文件rnrn源码这里粘贴长度不允许,传至github,maven下的工程结构很简单,希望各位大大能够帮忙看一下,弄了很久一直没弄好spring-mybatis的一个问题。rnhttps://github.com/Bonsen/Spring-SpringMVC-mybatis

没有更多推荐了,返回首页

私密
私密原因:
请选择设置私密原因
  • 广告
  • 抄袭
  • 版权
  • 政治
  • 色情
  • 无意义
  • 其他
其他原因:
120
出错啦
系统繁忙,请稍后再试