mirror of
http://git.pig4cloud.com/pig/pigx.git
synced 2026-11-08 12:39:05 +08:00
♻️ Refactoring code. 租户ttl切换清空拦截器修改为过滤器
This commit is contained in:
1 parent
59ce474e20
commit
e9f625d6eb
6 files changed
+38
-51
No files matched your search
@@ -19,7 +19,7 @@
|
||||
<properties>
|
||||
<pigx.version>4.5.0</pigx.version>
|
||||
<mybatis-plus.version>3.5.1</mybatis-plus.version>
|
||||
<dynamic-ds.version>3.4.1</dynamic-ds.version>
|
||||
<dynamic-ds.version>3.5.2</dynamic-ds.version>
|
||||
<druid.version>1.2.9</druid.version>
|
||||
<hutool.version>5.8.5</hutool.version>
|
||||
<mysql.connector.version>8.0.30</mysql.connector.version>
|
||||
|
||||
+1
-1
@@ -40,6 +40,6 @@ public interface PigxBaseMapper<T> extends BaseMapper<T> {
|
||||
* @param scope 数据权限范围
|
||||
* @return Integer
|
||||
*/
|
||||
Integer selectCountByScope(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, DataScope scope);
|
||||
Long selectCountByScope(@Param(Constants.WRAPPER) Wrapper<T> queryWrapper, DataScope scope);
|
||||
|
||||
}
|
||||
+2
-3
@@ -28,7 +28,6 @@ import org.springframework.boot.context.properties.EnableConfigurationProperties
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
@@ -58,8 +57,8 @@ public class DynamicDataSourceAutoConfiguration {
|
||||
}
|
||||
|
||||
@Bean
|
||||
public WebMvcConfigurer webMvcConfigurer() {
|
||||
return new ClearTtlDsConfiguration();
|
||||
public ClearTtlDataSourceFilter clearTtlDsFilter() {
|
||||
return new ClearTtlDataSourceFilter();
|
||||
}
|
||||
|
||||
}
|
||||
+34
@@ -0,0 +1,34 @@
|
||||
package com.pig4cloud.pigx.common.datasource.config;
|
||||
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.web.filter.GenericFilterBean;
|
||||
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/12/11
|
||||
* <p>
|
||||
* 清空上文的DS 设置避免污染当前线程
|
||||
*/
|
||||
public class ClearTtlDataSourceFilter extends GenericFilterBean implements Ordered {
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
||||
throws IOException, ServletException {
|
||||
DynamicDataSourceContextHolder.clear();
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
DynamicDataSourceContextHolder.clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getOrder() {
|
||||
return Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
}
|
||||
-17
@@ -1,17 +0,0 @@
|
||||
package com.pig4cloud.pigx.common.datasource.config;
|
||||
|
||||
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
|
||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/12/11
|
||||
*/
|
||||
public class ClearTtlDsConfiguration implements WebMvcConfigurer {
|
||||
|
||||
@Override
|
||||
public void addInterceptors(InterceptorRegistry registry) {
|
||||
registry.addInterceptor(new ClearTtlDsInterceptor()).addPathPatterns("/**");
|
||||
}
|
||||
|
||||
}
|
||||
-29
@@ -1,29 +0,0 @@
|
||||
package com.pig4cloud.pigx.common.datasource.config;
|
||||
|
||||
import com.baomidou.dynamic.datasource.toolkit.DynamicDataSourceContextHolder;
|
||||
import org.springframework.web.servlet.HandlerInterceptor;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
/**
|
||||
* @author lengleng
|
||||
* @date 2020/12/11
|
||||
* <p>
|
||||
* 清空上文的DS 设置避免污染当前线程
|
||||
*/
|
||||
public class ClearTtlDsInterceptor implements HandlerInterceptor {
|
||||
|
||||
@Override
|
||||
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
|
||||
DynamicDataSourceContextHolder.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
|
||||
Exception ex) {
|
||||
DynamicDataSourceContextHolder.clear();
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user