[Solved] Mybatis-plus Error: mybatisplus-Invalid bound statement (not found): com.integration.dao.ApiDao.getList

Error reporting background

Use Mybatis-Plus, but some interfaces still need to write their own SQL, when calling the interface that writes their own SQL, as in the title com.integration.dao.ApiDao.getList, an error occurs.
Mybatis-PlusIt is not used much, this is the first time to build Mybatis-Plusan environment by myself.

Error reporting content

2022-08-24 14:04:21.574 ERROR 21440 --- [nio-8001-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.integration.dao.ApiDao.getApiList] with root cause

org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.integration.dao.ApiDao.getApiList
	at com.baomidou.mybatisplus.core.override.PageMapperMethod$SqlCommand.<init>(PageMapperMethod.java:261) ~[mybatis-plus-core-3.0.7.1.jar:3.0.7.1]
	at com.baomidou.mybatisplus.core.override.PageMapperMethod.<init>(PageMapperMethod.java:58) ~[mybatis-plus-core-3.0.7.1.jar:3.0.7.1]
	at com.baomidou.mybatisplus.core.override.PageMapperProxy.cachedMapperMethod(PageMapperProxy.java:70) ~[mybatis-plus-core-3.0.7.1.jar:3.0.7.1]
	at com.baomidou.mybatisplus.core.override.PageMapperProxy.invoke(PageMapperProxy.java:63) ~[mybatis-plus-core-3.0.7.1.jar:3.0.7.1]
	at com.sun.proxy.$Proxy79.getApiList(Unknown Source) ~[na:na]
	at com.integration.service.impl.ApiServiceImpl.getApiList(ApiServiceImpl.java:30) ~[classes/:na]
	at com.integration.controller.ApiController.getApiList(ApiController.java:36) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_281]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_281]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_281]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_281]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:190) ~[spring-web-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:138) ~[spring-web-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:892) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:797) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:652) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.1.17.RELEASE.jar:5.1.17.RELEASE]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733) ~[tomcat-embed-core-9.0.37.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) ~[tomcat-embed-core-9.0.37.jar:9.0.37]

For developers who have used Mybatis, I believe that this error is not unfamiliar, the reason for this error is necessarily the interface of the Dao layer, and the Mapper.xml file Sql, did not find the corresponding mapping.

I think there are two ways to troubleshoot.

  • Determine whether Mybatis reads the relevant Xml file, generally by configuring mybatis.mapper-locations: classpath:mybatis/*.xml to read the Xml file.
  • Make sure that the method names and return values in the Dao interface correspond exactly to the Sql method names and return values in the Xml.

I also use the above two troubleshooting ideas to troubleshoot, and after troubleshooting, I think there is no problem

Mybatis configuration.

mybatis:
  configuration:
    map-underscore-to-camel-case: true
  mapper-locations: classpath:mybatis/*.xml

XML file path

Dao layer method

List<IomImApiBo> getList();

XML file (SQL)

    <select id="getList" resultType="com.integration.entity.IomImApiBo">
        select a.api_key,
               b.`value`
        from iom_im_api a
                 left join iom_im_api_value b on a.value_id = b.id
    </select>

Problems found

Solution:

Add the relevant configuration of mybatis-plus. Note that it is different from the configuration of mybatis….

mybatis-plus:
  mapper-locations: classpath:mybatis/*.xml

Read More: