springboot項(xiàng)目中mybatis-plus@Mapper注入失敗問題
更新時(shí)間:2024年07月19日 08:54:26 作者:EricFRQ
這篇文章主要介紹了springboot項(xiàng)目中mybatis-plus@Mapper注入失敗問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
先排除以下幾個(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: 0
3.模糊查詢某字段
/** * 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)文章
集成apollo動(dòng)態(tài)日志取締logback-spring.xml配置
這篇文章主要為大家介紹了集成apollo動(dòng)態(tài)日志取締logback-spring.xml配置的過程內(nèi)容詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助2022-02-02在spring中使用自定義注解注冊(cè)監(jiān)聽器的方法
本篇文章主要介紹了在spring中使用自定義注解注冊(cè)監(jiān)聽器的方法,本文就是在分析監(jiān)聽器回調(diào)原理的基礎(chǔ)上,在spring環(huán)境中使用自定義的注解實(shí)現(xiàn)一個(gè)監(jiān)聽器。小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-01-01Java實(shí)現(xiàn)圖片旋轉(zhuǎn)、指定圖像大小和水平翻轉(zhuǎn)
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)圖像旋轉(zhuǎn),指定圖像大小,水平翻轉(zhuǎn)圖像,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-02-02