三步教你解决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

mybatis+spring-boot出现Invalid bound statement (not found):问题

04-29

初学mybatis+spring-boot整合,报错如下:rn[code=java]org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.nx.zhjf.mapper.UserMapper.findUserByUsernamern [/code]rn我的代码结构如下:rn[img=http://img.bbs.csdn.net/upload/201704/29/1493469852_659574.png][/img][img=http://img.bbs.csdn.net/upload/201704/29/1493469861_915777.png][/img]rnapplication.ym配置文件如下:[code=java]rnspring:rn datasource:rn driver-class-name:org.postgresql.Driverrn url:jdbc:postgresql://localhost:5432/nxrn username:postgresrn password:postgresrn# schema:classpath:import.sqlrn tomcat:rn max-active:30rn max-wait:1000rn max-idle:20rn remove-abandoned-timeout:180rnmybatis:rn config-location:classpath:mybatis-config.xmlrnrn[/code]rnrnUserMapper.xml如下:rn[code=html]rnrnrnrn rn insert into t_user(username,age) values(#userName,jdbcType=VARCHAR,#age,jdbcType=NUMERIC)rn rnrn rn select * from t_user where id = #id,jdbcType=NUMERICrn rnrn rn update t_user setrn username = #userName,jdbcType=VARCHAR ,rn age = #age,jdbcType=NUMERICrn where id = #id,jdbcType=NUMERICrn rnrn rn delete from t_user where id = #id,jdbcType=NUMERICrn rnrn rn rn select * from t_user where username LIKE #patternrn rnrn rn SELECT COUNT(*) FROM t_userrn rnrn rn select * from t_userrn rnrnrnrn[/code]rnUserMapper.java如下:rn[code=java]rn@Mapperrnpublic interface UserMapper rn int save(User user);rnrn User selectById(Integer id);rnrn int updateById(User user);rnrn int deleteById(Integer id);rnrn List findUserByUsername(String username);rnrn int count();rnrn List queryAll();rnrn[/code]rnrn请大神帮我看下,哪里出问题了。rnrnrnrn

关于mybatis Invalid bound statement (not found) 问题

06-26

初学mybatis 现在系统是spring + mybatis rnapplicationContext.xml里面配置了Mapper 自动扫描rnrnrn rnrnrn然后定义了一个userMapper,里面就只有一个方法rnrn@Repository(value="userMapper")rnpublic interface UserMapper rn public List getAll();rnrnrn下面是userMapper.xmlrnrn rn select * from userrn rnrnrn下面是mybatis 配置文件rnrnrn rn rn rn rn rn rn rn rn rnrnrn我业务层定义了一个接口 UserService 然后 下面是实现类rnrn@Component(value="userServiceImpl")rn@Transactionalrnpublic class UserServiceImpl implements UserServicern rn private UserMapper userMapper;rn @Autowiredrn public void setUserMapper(UserMapper userMapper) rn this.userMapper = userMapper;rn rnrn public List getAll() rn return userMapper.getAll();rn rnrnrnrn我spring 配置文件加载完成后运行下面的代码可以获取结果rnUserServiceImpl userServiceImpl = (UserServiceImpl)PlatformContext.getApplicationContext().getBean("userServiceImpl");rnList lista = userServiceImpl.getAll();rnrn但是我现在又写了一个类 叫UserComponent 如下:rn@Component(value="userComponent")rnpublic class UserComponent rn private UserService userService;rn @Autowiredrn public void setUserService(UserService userService) rn this.userService = userService;rn rn public List getAll(Head head)rn return userService.getAll();rn rnrnrn我这个UserService直接注入了rnUserComponent userComponent = (UserComponent)PlatformContext.getApplicationContext().getBean("userComponent");rnList list = userComponent.getAll();rnrn我像这样调用的时候就不行了,只是多加了一层啊,这是为啥,求解!rnrn[b]下面是异常信息:[/b]rn[b]org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.yolly.platform.user.service.UserService.getAll[/b]rn at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:178)rn at org.apache.ibatis.binding.MapperMethod.(MapperMethod.java:38)rn at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:49)rn at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:42)rn at $Proxy12.getAll(Unknown Source)rn at com.yolly.platform.user.component.UserComponent.getAll(UserComponent.java:25)rn at com.yolly.core.main.Server$ServerHandler.messageReceived(Server.java:101)rn at org.apache.mina.core.filterchain.DefaultIoFilterChain$TailFilter.messageReceived(DefaultIoFilterChain.java:690)rn at org.apache.mina.core.filterchain.DefaultIoFilterChain.callNextMessageReceived(DefaultIoFilterChain.java:417)rn at org.apache.mina.core.filterchain.DefaultIoFilterChain.access$1200(DefaultIoFilterChain.java:47)rn at org.apache.mina.core.filterchain.DefaultIoFilterChain$EntryImpl$1.messageReceived(DefaultIoFilterChain.java:765)rn at org.apache.mina.core.filterchain.IoFilterEvent.fire(IoFilterEvent.java:74)rn at org.apache.mina.core.session.IoEvent.run(IoEvent.java:63)rn at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTask(OrderedThreadPoolExecutor.java:769)rn at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.runTasks(OrderedThreadPoolExecutor.java:761)rn at org.apache.mina.filter.executor.OrderedThreadPoolExecutor$Worker.run(OrderedThreadPoolExecutor.java:703)rn at java.lang.Thread.run(Thread.java:662)rn[b]Caused by: java.lang.IllegalArgumentException: Mapped Statements collection does not contain value for com.yolly.platform.user.service.UserService.getAll[/b]rn at org.apache.ibatis.session.Configuration$StrictMap.get(Configuration.java:775)rn at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:615)rn at org.apache.ibatis.session.Configuration.getMappedStatement(Configuration.java:608)rn at org.apache.ibatis.binding.MapperMethod$SqlCommand.(MapperMethod.java:176)rn ... 16 morernrnrnrnrnrnrn

mybatis错误Invalid bound statement (not found)万分感谢!

12-15

0.问题说明:n我是一名菜鸟,最近使用spring-mvc ,spring,mybatis框架n这两天出现一个错误一直搞不定,心好累,恳请前辈帮帮忙n1. 异常n```n org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.misscandy.inter.UserMapper.findAllUsersn org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:978)n org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:868)n javax.servlet.http.HttpServlet.service(HttpServlet.java:647)n org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:842)n javax.servlet.http.HttpServlet.service(HttpServlet.java:728)n org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)n org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)n org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)n```nnn n n2.我的配置文件n n```n n n n n nn n n n n n n```n3.接口nUserMapper.javannn```n package com.misscandy.inter;nnimport java.util.Vector;nnimport com.misscandy.entity.User;nimport com.misscandy.mapper.Mapper;nnn@Mappernpublic interface UserMapper n void addUser(User user);n //void deleteUser(User user);n //void updateDept(User user);n User findUserByName(String userName);n Vector findAllUsers();n //List> findValue();n //List findValues();nnn```nn4.UserMapper.xmlnnn```n nn nnn n n n n n n n n n n nn n n select user_id,user_name,image_src,age,sex,type from users where user_name = #userNamen n nn n n select user_id,user_name,age,sex,type from usersn n nn n n insert into users n (user_name,password,sex,age,type)n valuesn (#userName,#password,#sex,#age,1)n n nnnnn```nnn

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