数据分离-未登录状态兼容
This commit is contained in:
parent
9b7c24ef7f
commit
efdad0defb
@ -8,8 +8,9 @@ public class MyTenantFactory implements TenantFactory {
|
||||
|
||||
public Object[] getTenantIds() {
|
||||
RequestAttributes attributes = RequestContextHolder.getRequestAttributes();
|
||||
Long tenantId = (Long) attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
|
||||
if (tenantId != null) {
|
||||
Object attribute = attributes.getAttribute("tenantId", RequestAttributes.SCOPE_REQUEST);
|
||||
if (attribute != null) {
|
||||
Long tenantId = Long.valueOf(attribute.toString());
|
||||
return new Object[]{tenantId};
|
||||
} else {
|
||||
return new Object[]{};
|
||||
|
||||
@ -4,14 +4,15 @@ import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.cdzy.common.model.StaffDto;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
|
||||
public class TenantInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request
|
||||
, HttpServletResponse response, Object handler) throws Exception {
|
||||
public boolean preHandle(@NotNull HttpServletRequest request
|
||||
, @NotNull HttpServletResponse response, @NotNull Object handler) throws Exception {
|
||||
|
||||
//通过 request 去获取租户 ID
|
||||
if (StpUtil.isLogin()) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user