feat: 引入jpa多租户

初步引入jpa多租户
V0.5.x
tiger 2023-07-15 15:44:00 +08:00
parent 8c887eb350
commit 2798c5f879
3 changed files with 60 additions and 2 deletions

View File

@ -0,0 +1,22 @@
package cc.iotkit.common.web.config;
import cc.iotkit.common.web.interceptor.TenantInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
/**
* ID.
*
* @author Tiger Chen
* created on 2023/7/15 14:48
*/
@Configuration
public class TenantConfig implements WebMvcConfigurer {
@Override
public void addInterceptors(InterceptorRegistry registry) {
registry.addInterceptor(new TenantInterceptor());
}
}

View File

@ -0,0 +1,38 @@
package cc.iotkit.common.web.interceptor;
import cn.dev33.satoken.context.SaHolder;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* id
*
* @author Tiger Chen
* created on 2023/7/15 14:26
*/
public class TenantInterceptor implements HandlerInterceptor {
public static final String TENANT_ID = "Tenant-Id";
@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
if (request.getHeader(TENANT_ID) != null) {
String tenantId = request.getHeader(TENANT_ID);
SaHolder.getStorage().set("tenantId", tenantId);
}
return true;
}
@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
}
@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) throws Exception {
}
}

View File

@ -212,8 +212,6 @@
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-core</artifactId>
<version>5.8.3</version>
<scope>compile</scope>
</dependency>