diff --git a/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MyBatisPlusExtensionProperties.java b/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MyBatisPlusExtensionProperties.java index 303db90..4d046db 100644 --- a/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MyBatisPlusExtensionProperties.java +++ b/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MyBatisPlusExtensionProperties.java @@ -59,6 +59,11 @@ public class MyBatisPlusExtensionProperties { */ private PaginationProperties pagination; + /** + * 启用乐观锁插件 + */ + private boolean optimisticLockerEnabled = false; + /** * 启用防全表更新与删除插件 */ @@ -181,6 +186,14 @@ public void setPagination(PaginationProperties pagination) { this.pagination = pagination; } + public boolean isOptimisticLockerEnabled() { + return optimisticLockerEnabled; + } + + public void setOptimisticLockerEnabled(boolean optimisticLockerEnabled) { + this.optimisticLockerEnabled = optimisticLockerEnabled; + } + public boolean isBlockAttackPluginEnabled() { return blockAttackPluginEnabled; } diff --git a/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MybatisPlusAutoConfiguration.java b/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MybatisPlusAutoConfiguration.java index 72f89b1..50cec97 100644 --- a/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MybatisPlusAutoConfiguration.java +++ b/continew-starter-data/continew-starter-data-mp/src/main/java/top/continew/starter/data/mp/autoconfigure/MybatisPlusAutoConfiguration.java @@ -20,10 +20,7 @@ import com.baomidou.mybatisplus.autoconfigure.MybatisPlusPropertiesCustomizer; import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.handler.DataPermissionHandler; -import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.DataPermissionInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor; -import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; +import com.baomidou.mybatisplus.extension.plugins.inner.*; import jakarta.annotation.PostConstruct; import org.mybatis.spring.annotation.MapperScan; import org.slf4j.Logger; @@ -96,6 +93,10 @@ public MybatisPlusInterceptor mybatisPlusInterceptor(MyBatisPlusExtensionPropert if (null != paginationProperties && paginationProperties.isEnabled()) { interceptor.addInnerInterceptor(this.paginationInnerInterceptor(paginationProperties)); } + // 乐观锁插件 + if (properties.isOptimisticLockerEnabled()) { + interceptor.addInnerInterceptor(new OptimisticLockerInnerInterceptor()); + } // 防全表更新与删除插件 if (properties.isBlockAttackPluginEnabled()) { interceptor.addInnerInterceptor(new BlockAttackInnerInterceptor());