From 49594717f975d1d9ac5418f72430f816204db58e Mon Sep 17 00:00:00 2001 From: memorylkf <312904636@qq.com> Date: Mon, 22 Dec 2025 13:43:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:[=E5=9F=BA=E7=A1=80=E9=85=8D=E7=BD=AE]=20my?= =?UTF-8?q?batisplus=E9=85=8D=E7=BD=AE=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hxhq-common/hxhq-common-core/pom.xml | 6 +++ .../hxhq/common/core/config/MyBatisPlusConfig.java | 51 +++++++++++++++------- .../hxhq/common/security/utils/SecurityUtils.java | 15 +++++++ .../main/java/com/hxhq/business/domain/MjyTz.java | 4 -- 4 files changed, 57 insertions(+), 19 deletions(-) diff --git a/hxhq-common/hxhq-common-core/pom.xml b/hxhq-common/hxhq-common-core/pom.xml index 69d0b65..de321a9 100644 --- a/hxhq-common/hxhq-common-core/pom.xml +++ b/hxhq-common/hxhq-common-core/pom.xml @@ -112,6 +112,12 @@ mybatis-plus-boot-starter + + + com.hxhq + hxhq-common-security + + diff --git a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java index 6b89d21..4c050e7 100644 --- a/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java +++ b/hxhq-common/hxhq-common-core/src/main/java/com/hxhq/common/core/config/MyBatisPlusConfig.java @@ -1,45 +1,66 @@ package com.hxhq.common.core.config; import com.baomidou.mybatisplus.annotation.DbType; +import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler; +import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.BlockAttackInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.OptimisticLockerInnerInterceptor; import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.transaction.annotation.EnableTransactionManagement; /** * @author memory */ @Configuration +@EnableTransactionManagement(proxyTargetClass = true) public class MyBatisPlusConfig { + @Bean + public MybatisPlusInterceptor mybatisPlusInterceptor() + { + MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor(); + // 分页插件 + interceptor.addInnerInterceptor(paginationInnerInterceptor()); + // 乐观锁插件 + interceptor.addInnerInterceptor(optimisticLockerInnerInterceptor()); + // 阻断插件 + interceptor.addInnerInterceptor(blockAttackInnerInterceptor()); + return interceptor; + } + /** - * 分页插件 + * 分页插件,自动识别数据库类型 https://baomidou.com/guide/interceptor-pagination.html */ - @Bean - public PaginationInnerInterceptor paginationInterceptor() { - PaginationInnerInterceptor paginationInterceptor = new PaginationInnerInterceptor(); - // 设置请求的页面大于最大页后是否进行回滚, true回滚, false继续 - paginationInterceptor.setOverflow(false); - // 设置最大单页限制数量, 默认 500 条, -1 不受限制 - paginationInterceptor.setDbType(DbType.MYSQL); - paginationInterceptor.setMaxLimit(-1L); - return paginationInterceptor; + public PaginationInnerInterceptor paginationInnerInterceptor() + { + PaginationInnerInterceptor paginationInnerInterceptor = new PaginationInnerInterceptor(); + // 设置数据库类型为mysql + paginationInnerInterceptor.setDbType(DbType.MYSQL); + // 设置最大单页限制数量,默认 500 条,-1 不受限制 + paginationInnerInterceptor.setMaxLimit(-1L); + return paginationInnerInterceptor; } /** - * 乐观锁插件 + * 乐观锁插件 https://baomidou.com/guide/interceptor-optimistic-locker.html */ - @Bean - public OptimisticLockerInnerInterceptor optimisticLockerInterceptor() { + public OptimisticLockerInnerInterceptor optimisticLockerInnerInterceptor() + { return new OptimisticLockerInnerInterceptor(); } - /** * 如果是对全表的删除或更新操作,就会终止该操作 https://baomidou.com/guide/interceptor-block-attack.html */ - public BlockAttackInnerInterceptor blockAttackInnerInterceptor() { + public BlockAttackInnerInterceptor blockAttackInnerInterceptor() + { return new BlockAttackInnerInterceptor(); } + + @Bean + public MetaObjectHandler metaObjectHandler(){ + return new BaseMetaObjectHandler(); + } } diff --git a/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/utils/SecurityUtils.java b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/utils/SecurityUtils.java index bd8d9d9..ccb2df9 100644 --- a/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/utils/SecurityUtils.java +++ b/hxhq-common/hxhq-common-security/src/main/java/com/hxhq/common/security/utils/SecurityUtils.java @@ -25,6 +25,21 @@ public class SecurityUtils } /** + * 获取用户(不存在就返回空对象) + **/ + public static LoginUser getLoginUserOfEmpty() + { + try + { + return (LoginUser) SecurityContextHolder.get(SecurityConstants.LOGIN_USER, LoginUser.class); + } + catch (Exception e) + { + return new LoginUser(); + } + } + + /** * 获取用户名称 */ public static String getUsername() diff --git a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/MjyTz.java b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/MjyTz.java index 71e5b44..07631f5 100644 --- a/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/MjyTz.java +++ b/hxhq-modules/hxhq-system/src/main/java/com/hxhq/business/domain/MjyTz.java @@ -45,10 +45,6 @@ public class MjyTz extends MpBaseEntity /** 操作量单位 */ private String czldw; - public static long getSerialVersionUID() { - return serialVersionUID; - } - public Long getMjyId() { return mjyId; }