mybatisplus报错:invalid bound statement(not found)
有的同学,在搭建mybatis plus项目时,遇到invalid bound statement (not found)的问题。
实质上是mapper接口和mapper.xml没有映射起来。
这种情况,常见的问题有以下几个:
1、mapper.xml 里面的 namespace与实际的mapper类路径不一致
- 这个有个快捷的检测办法就是按住ctrl键,然后点击namespace里面的包名
- 如果能跳到对应的类,那就说明没有问题
- 如果你用的idea也是同样的办法,idea的包名是可以分段的,只要是能点进去都没问题
2、mapper接口的函数名和mapper.xml里面的标签id不一致
这个问题也很常见,最好的办法还是粘贴复制过去,这样可以确保没有问题。
第1点和2点都是关于拼写错误的情况。
3、构建没有进去
请看一下target文件夹下面这些是否存在,没有请重新构建。
4、查看扫包是否添加
我的是添加在springboot启动类上面的。
5、检查配置文件是否写错
#这个地方是否写错
mapper-locations: classpath:mybatis/mapper/**/*.xml
mybatis-plus可以是这样的配置-数组形式:
mybatis-plus: mapper-locations: - classpath:mybatis/mapper/**/*.xml
或者是
mybatis-plus: mapper-locations: classpath:mybatis/**/*mapper.xml
注意:这个key是mapper-locations 而不是mapper-location:
其他配置:
mybatis-plus: global-config: #主键类型 0:"数据库id自增", 1:"用户输入id",2:"全局唯一id (数字类型唯一id)", 3:"全局唯一id uuid"; id-type: 0 #字段策略 0:"忽略判断",1:"非 null 判断"),2:"非空判断" field-strategy: 0 #驼峰下划线转换 db-column-underline: true #刷新mapper 调试神器 refresh-mapper: true #数据库大写下划线转换 #capital-mode: true #序列接口实现类配置 #key-generator: com.baomidou.springboot.xxx #逻辑删除配置(下面3个配置) #logic-delete-value: 0 # 逻辑已删除值(默认为 1) #logic-not-delete-value: 1 # 逻辑未删除值(默认为 0) #自定义填充策略接口实现 #meta-object-handler: com.zhengqing.config.mymetaobjecthandler #自定义sql注入器 #sql-injector: com.baomidou.springboot.xxx configuration: # sql 解析缓存,开启后多租户 @sqlparser 注解生效 #sql-parser-cache: true configuration: # 驼峰转换 从数据库列名到java属性驼峰命名的类似映射 map-underscore-to-camel-case: true # 是否开启缓存 cache-enable: false # 如果查询结果中包含空值的列,则 mybatis 在映射的时候,不会映射这个字段 #call-setters-on-nulls: true # 打印sql log-impl: org.apache.ibatis.logging.stdout.stdoutimpl
总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持代码网。
发表评论