Skip to content

Commit

Permalink
feat(data/mp): 新增乐观锁插件启用配置(默认关闭)
Browse files Browse the repository at this point in the history
  • Loading branch information
Charles7c committed Sep 10, 2024
1 parent f3f57b8 commit 08ef09c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ public class MyBatisPlusExtensionProperties {
*/
private PaginationProperties pagination;

/**
* 启用乐观锁插件
*/
private boolean optimisticLockerEnabled = false;

/**
* 启用防全表更新与删除插件
*/
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down

0 comments on commit 08ef09c

Please sign in to comment.