0
点赞
收藏
分享

微信扫一扫

bug记录:项目中mybatis-plus@Mapper注入失败

先排除以下几个原因:

1.application.properties的配置mapper-locations路径正确

2.springboot启动类上加@MapperScan(value="xxxx")

3.mapper.xml里的namespace配置正确

4.xxxmapper接口使用了@Mapper

如果都不是

请降低mybatis-plus的版本!高版本是坑

 <!-- mybatis-plus -->

       <dependency>

           <groupId>com.baomidou</groupId>

           <artifactId>mybatis-plus-boot-starter</artifactId>

           <version>3.0.5</version>

       </dependency>

补充几个mybatisplus的小知识点:

自定义库表不存在的字段

/**

 * 子分类(自定义)

 */

@TableField(exist = false)

private List<CategoryEntity> children;

逻辑删除的标记注解

(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

模糊查询某字段

/**

* 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));

举报

相关推荐

0 条评论