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;
  1. 逻辑删除的标记注解
    (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: 0
  1. 模糊查询某字段
 /**
 * public static final String EQUAL = "%s=#{%s}";等于
 */
    
/**
 * public static final String NOT_EQUAL = "%s&lt;&gt;#{%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));
  • 3
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值