Tag Archives: Mybatis-plus Error

[Solved] mybatis plus Error: Invalid bound statement (not found)

Some students encountered the problem of “Invalid bound statement (not found)” when building the mybatis plus project, it is essentially that the mapper interface and the mapper.xml is not mapped.

In this case, the common problems are as follows:

1, mapper.xml inside the namespace and the actual mapper class path is not consistent.
There is a quick way to detect this is to hold down the ctrl key, and then click the package name inside the namespace, if you can jump to the corresponding class, it means there is no problem, if you use the IDEA is the same way, IDEA package name can be segmented, as long as you can point in are no problem.

2, mapper interface function name and mapper.xml inside the label id is not consistent.
This problem is also very common, the best way is to paste and copy it, so as to ensure that there is no problem.

The first point and 2 points are about spelling errors.

3, the build did not go in, please see if these exist below the target folder, no please rebuild

4. Check whether package scanning is added. I added it to the spring boot startup class.

5. Check whether the configuration file is written incorrectly or not

#Is this place wrongly written?

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

Mybatis-plus can be configured as an array:

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

Or

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

Note that the key is mapper-locations and not mapper-locations:

Other configurations:


mybatis-plus:
  global-config:
    #primary-key-type 0: "Database ID self-incrementing", 1: "User input ID", 2: "Global unique ID (numeric unique ID)", 3: "Global unique ID UUID";
    id-type: 0
    #field-strategy 0: "Ignore judgment",1: "Non-NULL judgment"),2: "Non-Null judgment"
    field-strategy: 0
    #hump-underline conversion
    db-column-underline: true
    #refresh-mapper debugging artifact
    refresh-mapper: true
    #database capital-underline conversion
    #capital-mode: true 
    #sequence interface implementation class configuration    
	#key-generator: com.baomidou.springboot.xxx 
    #logic-delete-configuration (the following 3 configurations)
    #logic-delete-value: 0 # logical-delete value (default is 1)    
	#logic-not-delete-value: 1 # logical-not-delete value (default is 0)    
	# Custom fill policy interface implementation    
	#meta-object-handler: com.zhengqing.config.   
	#custom SQL injector   
	#sql-injector: com.baomidou.springboot.xxx configuration:      
    #SQL parsing cache, multi-tenant @SqlParser annotation takes effect when enabled
    #sql-parser-cache: true
  configuration:
    # hump conversion Similar mapping from database column names to Java property hump naming  
    map-underscore-to-camel-case: true
    # Whether to enable caching
    cache-enable: false
    # If the query contains a column with a null value, MyBatis will not map this field when mapping        
	#call-setters-on-nulls: true  
    # 打印sql
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl

mybatis-plus Common Error and Their Solution

2021/7/9


Error 1: there is no @EnumValue annotation when writing enumeration class

Solution 1: @EnumValueis an annotation supported after mybatis-plus version 3.0

 

Error 2:

java.lang.annotation.AnnotationFormatError: Invalid default: public abstract java.lang.Class org.mybatis.spring.annotation.MapperScan.factoryBean()

Solution 2:

Modify the dependency from

<dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus</artifactId>
            <version>3.3.2</version>
        </dependency>

to

 <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.0.5</version>
        </dependency>

 

Error 3:
java.lang.IllegalStateException: Failed to load ApplicationContext
Caused by: org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘***’: Unsatisfied dependency

Solution 3:

Delete the dependency of mybaits

 <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>1.1.1</version>
        </dependency>

 

Error 4:

The list() method reports red, indicating that the parameter is missing,

Solution 4:

View source code

Method does require parameters

View official documents

It may be due to the version problem. In the latest version, you do not need to pass the parameter. The parameter should be null

Problem-solving

 

Error 5:

java.lang.IllegalArgumentException: No enum constant com.book.bookshop.entity.enums.Suit.1

Solution 5:

Removing spring-boot-devtools, this plug-in will cause many problems. It is estimated that it should be the main reason

[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