springboot項(xiàng)目中mybatis-plus@Mapper注入失敗問題
先排除以下幾個(gè)原因
- 1.application.properties的配置
mapper-locations路徑正確 - 2.springboot啟動(dòng)類上加
@MapperScan(value="xxxx") - 3.mapper.xml里的
namespace配置正確 - 4.xxxmapper接口使用了
@Mapper
如果都不是
請(qǐng)降低mybatis-plus的版本!高版本哈是坑!比如我之前用的3.4.1,要吐了,找了倆小時(shí)bug。
可以換下面的這個(gè):
<!-- mybatis-plus -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.0.5</version>
</dependency>補(bǔ)充幾個(gè)mybatisplus的小知識(shí)點(diǎn)
1.自定義庫表不存在的字段
/** * 子分類(自定義) */ @TableField(exist = false) private List<CategoryEntity> children;
2.邏輯刪除的標(biāo)記注解
(1)、注解標(biāo)記
@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的數(shù)據(jù):
//錯(cuò)誤寫法: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));總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
- SpringBoot同時(shí)集成Mybatis和Mybatis-plus框架
- SpringBoot+MyBatis-Plus實(shí)現(xiàn)分頁示例
- Springboot整合mybatis-plus使用pageHelper進(jìn)行分頁(使用步驟)
- SpringBoot+MyBatis-Plus實(shí)現(xiàn)分頁的項(xiàng)目實(shí)踐
- springboot集成mybatis-plus全過程
- Springboot集成Mybatis-plus、ClickHouse實(shí)現(xiàn)增加數(shù)據(jù)、查詢數(shù)據(jù)功能
- springboot+mybatis-plus實(shí)現(xiàn)自動(dòng)建表的示例
- SpringBoot中使用MyBatis-Plus實(shí)現(xiàn)分頁接口的詳細(xì)教程
- SpringBoot?mybatis-plus使用json字段實(shí)戰(zhàn)指南
- springboot3.2整合mybatis-plus詳細(xì)代碼示例
- 全網(wǎng)最新springboot整合mybatis-plus的過程
相關(guān)文章
IntelliJ IDEA配置java環(huán)境及解決IDEA不能直接運(yùn)行單個(gè)JAVA文件的問題
這篇文章主要介紹了IntelliJ IDEA配置java環(huán)境及解決IDEA不能直接運(yùn)行單個(gè)JAVA文件的問題,本文通過圖文并茂的形式給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-07-07
Spring Bean實(shí)例化實(shí)現(xiàn)過程解析
這篇文章主要介紹了Spring Bean實(shí)例化實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-02-02
Java從零實(shí)現(xiàn)超市會(huì)員管理系統(tǒng)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)超市會(huì)員管理系統(tǒng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-12-12
Java實(shí)現(xiàn)大數(shù)運(yùn)算的實(shí)例代碼
這篇文章主要介紹了Java實(shí)現(xiàn)大數(shù)運(yùn)算的實(shí)例代碼,小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2017-06-06
如何用ObjectMapper將復(fù)雜Map轉(zhuǎn)換為實(shí)體類
這篇文章主要介紹了如何用ObjectMapper將復(fù)雜Map轉(zhuǎn)換為實(shí)體類的操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-08-08

