当前位置: 首页 > news >正文

茂南网站开发公司网站多少钱

茂南网站开发公司,网站多少钱,手表排行榜,制作网页时用什么实现动态效果switchRegion(切换地区)功能, 客户端可手动切换地区 , 查询不同的数据库, 后台根据地区切换数据库, 请求头添加region的key 配置类 import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.boot.jdbc.DataSourceBuilder; im…

switchRegion(切换地区)功能, 客户端可手动切换地区 , 查询不同的数据库, 后台根据地区切换数据库, 请求头添加region的key

配置类


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;import javax.sql.DataSource;
import java.util.HashMap;
import java.util.Map;/*** @author Wang*/
@Configuration
public class DynamicDataSourceConfig {@Bean@ConfigurationProperties(prefix = "spring.datasource.us")public DataSource usDataSource() {return DataSourceBuilder.create().build();}@Bean@ConfigurationProperties(prefix = "spring.datasource.ca")public DataSource caDataSource() {return DataSourceBuilder.create().build();}@Bean@ConfigurationProperties(prefix = "spring.datasource.other")public DataSource otherDataSource() {return DataSourceBuilder.create().build();}@Bean@Primarypublic DynamicDataSource dataSource(DataSource usDataSource, DataSource caDataSource, DataSource otherDataSource) {Map<Object, Object> targetDataSources = new HashMap<>(3);targetDataSources.put(DataSourceEnum.US.toString().toLowerCase(), usDataSource);targetDataSources.put(DataSourceEnum.CA.toString().toLowerCase(), caDataSource);targetDataSources.put(DataSourceEnum.OTHER.toString().toLowerCase(), otherDataSource);DynamicDataSource dynamicDataSource = new DynamicDataSource(usDataSource, targetDataSources);dynamicDataSource.afterPropertiesSet();return dynamicDataSource;}
}

import com.woodare.cdw.component.context.RequestContextHolder;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;import javax.sql.DataSource;
import java.util.Map;/*** @author Wang*/
public class DynamicDataSource extends AbstractRoutingDataSource {public DynamicDataSource(DataSource firstDataSource, Map<Object, Object> targetDataSources) {setDefaultTargetDataSource(firstDataSource);setTargetDataSources(targetDataSources);afterPropertiesSet();}@Overrideprotected Object determineCurrentLookupKey() {return RequestContextHolder.getRegion();}
}
public enum DataSourceEnum {/*** region*/US,CA,OTHER;
}

请求拦截器

import com.woodare.cdw.component.context.RequestContextHolder;
import com.woodare.cdw.core.HeaderCons;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.web.servlet.HandlerInterceptor;/*** @author Wang*/
public class RequestInterceptor implements HandlerInterceptor {@Overridepublic boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {String region = request.getHeader(HeaderCons.X_REGION);if (region != null) {RequestContextHolder.setRegion(region);}return true;}@Overridepublic void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {RequestContextHolder.clearRegion();}
}

import com.woodare.cdw.interceptor.RequestInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;/*** @author Wang*/
@Configuration
public class ResourceConfig implements WebMvcConfigurer {@Overridepublic void addInterceptors(InterceptorRegistry registry) {registry.addInterceptor(new RequestInterceptor());}
}

线程上下文

/*** @author Wang*/
public class RequestContextHolder {private RequestContextHolder(){}private static final ThreadLocal<String> REQUEST_HOLDER = new ThreadLocal<>();public static String getRegion() {return REQUEST_HOLDER.get();}public static void setRegion(String region) {REQUEST_HOLDER.set(region);}public static void clearRegion() {REQUEST_HOLDER.remove();}
}

application 配置

#jpa
spring.jpa.hibernate.ddl-auto=update
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.show-sql=true# PostgreSQL
spring.datasource.us.jdbc-url=jdbc:postgresql://127.0.0.1:5432/cdw_us
spring.datasource.us.pool-name=cdw_us
spring.datasource.us.username=postgres
spring.datasource.us.password=123
spring.datasource.us.driver-class-name=org.postgresql.Driverspring.datasource.ca.jdbc-url=jdbc:postgresql://127.0.0.1:5432/cdw_ca
spring.datasource.ca.pool-name=cdw_ca
spring.datasource.ca.username=postgres
spring.datasource.ca.password=123
spring.datasource.ca.driver-class-name=org.postgresql.Driverspring.datasource.other.jdbc-url=jdbc:postgresql://127.0.0.1:5432/cdw_other
spring.datasource.other.pool-name=cdw_other
spring.datasource.other.username=postgres
spring.datasource.other.password=123
spring.datasource.other.driver-class-name=org.postgresql.Driver
http://www.hkea.cn/news/998020/

相关文章:

  • 云南省住房与城乡建设厅网站关键词排名零芯互联排名
  • 山东坤泰建设集团网站手机百度搜索app
  • wordpress php推送示例seozou是什么意思
  • 做网站多久天津seo网站管理
  • 建设局查询网站网络上市场推广
  • 怎么做装修网站b2b多平台一键发布
  • ASP做网站源代码大专网络营销专业好不好
  • 网络公司网站 优帮云做网站排名服务热线
  • 制作网页设计软件列表案例谷歌seo 优化
  • wordpress网站备案上海搜索推广
  • 网站建设套餐有哪些安卓在线视频嗅探app
  • 做电影网站要买什么重庆seo网站哪家好
  • 广州北京网站建设公司网站外部优化的4大重点
  • 网站建设书优化大师是干什么的
  • 优秀的网站建设公司百度指数人群画像
  • wordpress企业中文模板太原seo哪家好
  • 广东网广东网站建设网站推广方案模板
  • 网站运营知识快手seo
  • 咖啡公司网站建设策划书微信营销方式
  • 柳江区城乡住房建设局网站上海seo优化服务公司
  • 西城企业网站建设企业网站怎么优化
  • 初学者做动态网站项目例子游戏特效培训机构排名
  • 汽车类网站搭建直链平台
  • 做网站遇到的困难总结网络营销软件代理
  • 做网站登录论坛外链代发
  • 东营专业网站建设公司排行青岛谷歌优化公司
  • 公众号和网站先做哪个口碑营销的形式
  • 长沙企业建网站费用关键词搜索推广排行榜
  • 怎么做网站端口代理沧州网络推广外包公司
  • php wordpress 目录seo课程培训机构