add
This commit is contained in:
@ -38,4 +38,9 @@ public class BaseConstant {
|
||||
* https请求
|
||||
*/
|
||||
public static final String HTTPS = "https://";
|
||||
|
||||
/**
|
||||
* 资源映射路径 前缀
|
||||
*/
|
||||
public static final String RESOURCE_PREFIX = "/resource";
|
||||
}
|
||||
|
@ -13,13 +13,13 @@ import lombok.Getter;
|
||||
public enum BaseEnum {
|
||||
|
||||
// 是
|
||||
YES("1" , "是"),
|
||||
YES("1", "是"),
|
||||
// 否
|
||||
NO("0" , "否"),
|
||||
NO("0", "否"),
|
||||
// 正常
|
||||
NORMAL("1" , "正常"),
|
||||
NORMAL("1", "正常"),
|
||||
// 不正常
|
||||
ABNORMAL("0" , "不正常");
|
||||
ABNORMAL("0", "不正常");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
@ -74,7 +74,7 @@ public class AjaxResult extends HashMap<String, Object> {
|
||||
* @return 成功消息
|
||||
*/
|
||||
public static AjaxResult success(Object data) {
|
||||
return AjaxResult.success("操作成功" , data);
|
||||
return AjaxResult.success("操作成功", data);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -31,11 +31,11 @@ public class ObjectUtil {
|
||||
// 得到此属性的值
|
||||
Object val = f.get(obj);
|
||||
// 只要有1个属性不为空,那么就不是所有的属性值都为空
|
||||
if(val != null) {
|
||||
if (val != null) {
|
||||
flag = false;
|
||||
break;
|
||||
}
|
||||
}catch (IllegalAccessException e){
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,7 @@ import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 全局跨域配置
|
||||
* 多数据源配置
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
|
@ -11,6 +11,8 @@ import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
/**
|
||||
* MybatisPlusConfig
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2023/5/8 11:18
|
||||
|
@ -1,11 +1,7 @@
|
||||
package com.qiaoba.common.database.factories;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.DbType;
|
||||
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
|
||||
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
|
||||
import com.qiaoba.common.database.config.DynamicDataSourceConfig;
|
||||
import com.qiaoba.common.database.config.DynamicDataSourceContext;
|
||||
import com.qiaoba.common.database.config.MybatisPlusConfig;
|
||||
import com.qiaoba.common.database.filters.DynamicDataSourceFilter;
|
||||
import com.qiaoba.common.database.properties.DefaultDataSourceProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
@ -1,14 +1,18 @@
|
||||
package com.qiaoba.common.database.filters;
|
||||
|
||||
import com.qiaoba.common.base.utils.TenantUtil;
|
||||
import com.qiaoba.common.database.config.DynamicDataSourceContext;
|
||||
import com.qiaoba.common.database.constants.DynamicDatasourceConstant;
|
||||
import com.qiaoba.common.base.utils.TenantUtil;
|
||||
import com.qiaoba.common.web.utils.ResponseUtil;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.web.filter.OncePerRequestFilter;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.servlet.*;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@ -21,17 +25,18 @@ import java.io.IOException;
|
||||
*/
|
||||
@Component
|
||||
@Order(-10000)
|
||||
public class DynamicDataSourceFilter implements Filter {
|
||||
public class DynamicDataSourceFilter extends OncePerRequestFilter {
|
||||
|
||||
@Resource
|
||||
private DynamicDataSourceContext dynamicDataSourceContext;
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
|
||||
protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException {
|
||||
//设置当前租户对应的数据库
|
||||
dynamicDataSourceContext.setDataSource(DynamicDatasourceConstant.DEFAULT_MASTER_DATASOURCE_KEY);
|
||||
// todo
|
||||
TenantUtil.setTenantId("1");
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
filterChain.doFilter(request, response);
|
||||
dynamicDataSourceContext.clearDataSource();
|
||||
TenantUtil.clearTenantId();
|
||||
}
|
||||
|
@ -6,7 +6,7 @@ import com.baomidou.mybatisplus.core.conditions.Wrapper;
|
||||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.core.toolkit.*;
|
||||
import com.baomidou.mybatisplus.core.toolkit.ReflectionKit;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.baomidou.mybatisplus.extension.toolkit.Db;
|
||||
import com.qiaoba.common.web.utils.BeanCopyUtil;
|
||||
@ -101,7 +101,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
* 批量插入(包含限制条数)
|
||||
*
|
||||
* @param entityList list
|
||||
* @param batchSize 最大调数
|
||||
* @param batchSize 最大调数
|
||||
* @return 结果
|
||||
*/
|
||||
default boolean insertBatch(Collection<T> entityList, int batchSize) {
|
||||
@ -113,7 +113,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
* 批量更新(包含限制条数)
|
||||
*
|
||||
* @param entityList list
|
||||
* @param batchSize 最大调数
|
||||
* @param batchSize 最大调数
|
||||
* @return 结果
|
||||
*/
|
||||
default boolean updateBatchById(Collection<T> entityList, int batchSize) {
|
||||
@ -125,7 +125,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
* 批量插入或更新(包含限制条数)
|
||||
*
|
||||
* @param entityList list
|
||||
* @param batchSize 最大调数
|
||||
* @param batchSize 最大调数
|
||||
* @return 结果
|
||||
*/
|
||||
default boolean insertOrUpdateBatch(Collection<T> entityList, int batchSize) {
|
||||
@ -135,6 +135,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 插入或更新
|
||||
*
|
||||
* @param entity entity
|
||||
* @return 结果
|
||||
*/
|
||||
@ -144,6 +145,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
|
||||
/**
|
||||
* 查询Vo by id
|
||||
*
|
||||
* @param id 主键
|
||||
* @return Vo
|
||||
*/
|
||||
@ -154,9 +156,9 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
/**
|
||||
* 根据 ID 查询
|
||||
*
|
||||
* @param id 主键
|
||||
* @param id 主键
|
||||
* @param voClass Vo
|
||||
* @param <C> 泛型
|
||||
* @param <C> 泛型
|
||||
* @return Vo
|
||||
*/
|
||||
default <C> C selectVoById(Serializable id, Class<C> voClass) {
|
||||
@ -180,9 +182,9 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
/**
|
||||
* 通过Ids 查询 list
|
||||
*
|
||||
* @param idList ids
|
||||
* @param idList ids
|
||||
* @param voClass Vo
|
||||
* @param <C> 泛型
|
||||
* @param <C> 泛型
|
||||
* @return list
|
||||
*/
|
||||
default <C> List<C> selectVoBatchIds(Collection<? extends Serializable> idList, Class<C> voClass) {
|
||||
@ -206,9 +208,9 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
/**
|
||||
* selectVoByMap
|
||||
*
|
||||
* @param map map
|
||||
* @param map map
|
||||
* @param voClass Vo
|
||||
* @param <C> 泛型
|
||||
* @param <C> 泛型
|
||||
* @return Vo
|
||||
*/
|
||||
default <C> List<C> selectVoByMap(Map<String, Object> map, Class<C> voClass) {
|
||||
@ -234,7 +236,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
*
|
||||
* @param wrapper 条件
|
||||
* @param voClass Vo
|
||||
* @param <C> 泛型
|
||||
* @param <C> 泛型
|
||||
* @return Vo
|
||||
*/
|
||||
default <C> C selectVoOne(Wrapper<T> wrapper, Class<C> voClass) {
|
||||
@ -260,7 +262,7 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
*
|
||||
* @param wrapper 条件
|
||||
* @param voClass Vo
|
||||
* @param <C> 泛型
|
||||
* @param <C> 泛型
|
||||
* @return list vo
|
||||
*/
|
||||
default <C> List<C> selectVoList(Wrapper<T> wrapper, Class<C> voClass) {
|
||||
@ -274,9 +276,9 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
/**
|
||||
* 分页查询Vo
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param page 分页对象
|
||||
* @param wrapper 条件
|
||||
* @param <P> 泛型
|
||||
* @param <P> 泛型
|
||||
* @return IPage
|
||||
*/
|
||||
default <P extends IPage<V>> P selectVoPage(IPage<T> page, Wrapper<T> wrapper) {
|
||||
@ -286,11 +288,11 @@ public interface BaseMapperPlus<M, T, V> extends BaseMapper<T> {
|
||||
/**
|
||||
* 分页查询Vo
|
||||
*
|
||||
* @param page 分页对象
|
||||
* @param page 分页对象
|
||||
* @param wrapper 条件
|
||||
* @param voClass Vo
|
||||
* @param <C> 泛型
|
||||
* @param <P> 泛型
|
||||
* @param <C> 泛型
|
||||
* @param <P> 泛型
|
||||
* @return IPage
|
||||
*/
|
||||
default <C, P extends IPage<C>> P selectVoPage(IPage<T> page, Wrapper<T> wrapper, Class<C> voClass) {
|
||||
|
@ -16,8 +16,8 @@ public class JdbcUtil {
|
||||
/**
|
||||
* 检查数据源是否可以连接
|
||||
*
|
||||
* @param driver 数据库驱动
|
||||
* @param url url
|
||||
* @param driver 数据库驱动
|
||||
* @param url url
|
||||
* @param username 用户名
|
||||
* @param password 密码
|
||||
* @return true = 是
|
||||
|
@ -219,13 +219,13 @@ public class RedisServiceImpl implements RedisService {
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> T getObject(String key, Class<T> clazz) {
|
||||
return (T) get(handleKey(key));
|
||||
return (T) get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("unchecked")
|
||||
public <T> List<T> getObjectList(String key, Class<T> clazz) {
|
||||
return (List<T>) get(handleKey(key));
|
||||
return (List<T>) get(key);
|
||||
}
|
||||
|
||||
private String handleKey(String key) {
|
||||
|
@ -0,0 +1,37 @@
|
||||
package com.qiaoba.common.web.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.web.cors.CorsConfiguration;
|
||||
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
|
||||
import org.springframework.web.filter.CorsFilter;
|
||||
|
||||
/**
|
||||
* 全局跨域配置
|
||||
*
|
||||
* @author ailanyin
|
||||
* @version 1.0
|
||||
* @since 2021/10/15 0015 下午 16:43
|
||||
*/
|
||||
@Configuration
|
||||
public class GlobalCorsConfig {
|
||||
|
||||
@Bean
|
||||
public CorsFilter corsFilter() {
|
||||
CorsConfiguration config = new CorsConfiguration();
|
||||
config.setAllowCredentials(true);
|
||||
// 设置访问源地址
|
||||
config.addAllowedOriginPattern("*");
|
||||
// 设置访问源请求头
|
||||
config.addAllowedHeader("*");
|
||||
// 设置访问源请求方法
|
||||
config.addAllowedMethod("*");
|
||||
// 有效期 半小时
|
||||
config.setMaxAge(1800L);
|
||||
// 添加映射路径,拦截一切请求
|
||||
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
|
||||
source.registerCorsConfiguration("/**", config);
|
||||
// 返回新的CorsFilter
|
||||
return new CorsFilter(source);
|
||||
}
|
||||
}
|
@ -195,7 +195,7 @@ public class BeanCopyUtil {
|
||||
*/
|
||||
private String genKey(Class<?> srcClass, Class<?> targetClass, Converter converter) {
|
||||
final StringBuilder key = StrUtil.builder()
|
||||
.append(srcClass.getName()).append('#').append(targetClass.getName());
|
||||
.append(srcClass.getName()).append('#').append(targetClass.getName());
|
||||
if (null != converter) {
|
||||
key.append('#').append(converter.getClass().getName());
|
||||
}
|
||||
|
@ -1 +0,0 @@
|
||||
null not found
|
@ -1,4 +1,5 @@
|
||||
org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
com.qiaoba.common.web.advice.ExceptionAdvice
|
||||
com.qiaoba.common.web.advice.ExceptionAdvice,\
|
||||
com.qiaoba.common.web.config.GlobalCorsConfig
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user