springboot项目中mybatis-plus@Mapper注入失败问题
作者:EricFRQ
这篇文章主要介绍了springboot项目中mybatis-plus@Mapper注入失败问题,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
先排除以下几个原因
- 1.application.properties的配置
mapper-locations路径正确 - 2.springboot启动类上加
@MapperScan(value="xxxx") - 3.mapper.xml里的
namespace配置正确 - 4.xxxmapper接口使用了
@Mapper
如果都不是
请降低mybatis-plus的版本!高版本哈是坑!比如我之前用的3.4.1,要吐了,找了俩小时bug。
可以换下面的这个:
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>补充几个mybatisplus的小知识点
1.自定义库表不存在的字段
/** * 子分类(自定义) */ @TableField(exist = false) private List<CategoryEntity> children;
2.逻辑删除的标记注解
(1)、注解标记
@TableLogic private int deleted;// 0-未删除 1-已删除
(2)、3.2.0版本以下的mybatis-plus需要加配置
@Bean
public ISqlInjector sqlInjector(){
return new LogicSqlInjector();
}(3)、application配置文件加声明
mybatis-plus:
global-config:
db-config:
logic-delete-value: 1
logic-not-delete-value: 03.模糊查询某字段
/**
* public static final String EQUAL = "%s=#{%s}";等于
*/
/**
* public static final String NOT_EQUAL = "%s<>#{%s}";不等于
*/
/**
* public static final String LIKE = "%s LIKE CONCAT('%%',#{%s},'%%')";% 两边 %
*/
/**
* public static final String LIKE_LEFT = "%s LIKE CONCAT('%%',#{%s})";% 左
*/
/**
* public static final String LIKE_RIGHT = "%s LIKE CONCAT(#{%s},'%%')";右 %
*/
@TableField(value = "task_name", condition = SqlCondition.LIKE)
private String taskName;4.查询案例
//查询method=1并且operation=2或者=3的数据:
//错误写法:where method=1 and operation=2 or operation=3
LambdaQueryWrapper<SysLog> qw = new LambdaQueryWrapper<>();
qw.eq(SysLog::getMethod, "1");
qw.eq(SysLog::getOperation, "2");
qw.or(i -> i.eq(SysLog::getOperation, "3"));
//正确写法(1) where method=1 and (operation=2 or operation=3)
qw.eq(SysLog::getMethod, "1").and(i -> i.eq(SysLog::getOperation, "2").or().eq(SysLog::getOperation, "3"));
//正确写法(2) where method=1 and (operation=2 or operation=3)
QueryWrapper<SysLog> wrapper = new QueryWrapper<>();
wrapper.eq("method","1").and(i->i.eq("operation","2").or().eq("operation",3));总结
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
- SpringBoot同时集成Mybatis和Mybatis-plus框架
- SpringBoot+MyBatis-Plus实现分页示例
- Springboot整合mybatis-plus使用pageHelper进行分页(使用步骤)
- SpringBoot+MyBatis-Plus实现分页的项目实践
- springboot集成mybatis-plus全过程
- Springboot集成Mybatis-plus、ClickHouse实现增加数据、查询数据功能
- springboot+mybatis-plus实现自动建表的示例
- SpringBoot中使用MyBatis-Plus实现分页接口的详细教程
- SpringBoot mybatis-plus使用json字段实战指南
- springboot3.2整合mybatis-plus详细代码示例
- 全网最新springboot整合mybatis-plus的过程
