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

今天遇到一個問題,代碼寫完之後,運行的時候網頁報錯:

WhitelabelError Page

Thisapplication has no explicit mapping for /error, so you are seeing this as afallback.

Thu Jul 27 19:22:24 CST 2017

There was an unexpected error (type=Internal Server Error,status=500).

Invalid bound statement (not found):com.LilyDianer.FastNews.dao.NewsDAO.selectByUserIdAndOffset


服務器給我報的錯是:

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.LilyDianer.FastNews.dao.NewsDAO.selectByUserIdAndOffset
at org.apache.ibatis.binding.MapperMethod$SqlCommand.<init>(MapperMethod.java:214) ~[mybatis-3.4.0.jar:3.4.0]
at org.apache.ibatis.binding.MapperMethod.<init>(MapperMethod.java:48) ~[mybatis-3.4.0.jar:3.4.0]
at org.apache.ibatis.binding.MapperProxy.cachedMapperMethod(MapperProxy.java:59) ~[mybatis-3.4.0.jar:3.4.0]
at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52) ~[mybatis-3.4.0.jar:3.4.0]
at com.sun.proxy.$Proxy56.selectByUserIdAndOffset(Unknown Source) ~[na:na]
at com.LilyDianer.FastNews.service.NewsService.getLatestNews(NewsService.java:23) ~[classes/:na]
at com.LilyDianer.FastNews.controller.HomeController.getNews(HomeController.java:29) ~[classes/:na]
at com.LilyDianer.FastNews.controller.HomeController.index(HomeController.java:43) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_77]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_77]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_77]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_77]
at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136) ~[spring-web-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:110) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:832) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:743) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:961) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:895) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:967) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:858) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:622) ~[tomcat-embed-core-8.0.33.jar:8.0.33]
at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:843) ~[spring-webmvc-4.2.6.RELEASE.jar:4.2.6.RELEASE]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:729) ~[tomcat-embed-core-8.0.33.jar:8.0.33]



然後我就很仔細的看了代碼,真的真的是沒有問題啊,代碼這麼簡單,真的不可能是我寫的問題。
然後就到處百度:

http://blog.csdn.net/zgmzyr/article/details/8044980

http://bbs.csdn.net/topics/390501284

http://blog.csdn.net/u010504064/article/details/47337307

http://www.cnblogs.com/softidea/p/6053980.html

方法都看了,試了,還是不對。


然後我看到了這篇 【http://www.cnblogs.com/jstarseven/p/5803697.html】

因爲我也是剛換的IDEA,所以我覺得他說的很有道理,於是我就回去檢查我的發佈文件:


可以看到,我的xml文件的位置並沒有如我所願的放到com下的dao包裏,所以mybatis是無法掃描到這個xml,因此就會報方法找不到的錯。


解決方法:我在resource包下新建了一個與DAO類包同名的包,然後把xml文件放進去:


得到的發佈目錄應該是這個樣子的:



然後我再運行,就正確了。

哎,這個IDEA真的是坑爹,

開始我是直接把xml文件放到DAO類的包下的,直接不識別。

然後我百度了一下,覺得應該是要放到resource包下的,但是因爲在resource上new的時候沒有找到Pakage,就選了一個Directory來替代,圖標也挺像的,呵呵,然後就是幾個小時找不出來到底是哪裏錯......

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章