springboot項目中mybatis-plus@Mapper注入失敗問題
更新時間:2024年07月19日 08:54:26 作者: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字段實戰(zhàn)指南
- springboot3.2整合mybatis-plus詳細代碼示例
- 全網最新springboot整合mybatis-plus的過程
相關文章
集成apollo動態(tài)日志取締logback-spring.xml配置
這篇文章主要為大家介紹了集成apollo動態(tài)日志取締logback-spring.xml配置的過程內容詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-02-02

