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

怎么找人做网站啊商城手机网站开发

怎么找人做网站啊,商城手机网站开发,唐山 网站建设,关于做甜品的网站多数据源(数据源进行切换) AbstractRoutingDataSource 根据用户定义的规则选择当前的数据源#xff0c;这样我们可以在执行查询之前#xff0c;设置使用的数据源。实现可动态路由的数据源#xff0c;在每次数据库查询操作前执行。它的抽象方法 determineCurrentLookupKey()…多数据源(数据源进行切换) AbstractRoutingDataSource 根据用户定义的规则选择当前的数据源这样我们可以在执行查询之前设置使用的数据源。实现可动态路由的数据源在每次数据库查询操作前执行。它的抽象方法 determineCurrentLookupKey() 决定使用哪个数据源。 1、application.yml中配置多个数据源 # Orderspring.datasource.order.urljdbc:mysql://localhost:3306/seata_order?useUnicodetruecharacterEncodingutf8allowMultiQueriestrueuseSSLfalsespring.datasource.order.usernamerootspring.datasource.order.password123456spring.datasource.order.driver-class-namecom.mysql.cj.jdbc.Driver# Storagespring.datasource.storage.urljdbc:mysql://localhost:3306/seata_storage?useUnicodetruecharacterEncodingutf8allowMultiQueriestrueuseSSLfalsespring.datasource.storage.usernamerootspring.datasource.storage.password123456spring.datasource.storage.driver-class-namecom.mysql.cj.jdbc.Driver# Payspring.datasource.pay.urljdbc:mysql://localhost:3306/seata_pay?useUnicodetruecharacterEncodingutf8allowMultiQueriestrueuseSSLfalsespring.datasource.pay.usernamerootspring.datasource.pay.password123456spring.datasource.pay.driver-class-namecom.mysql.cj.jdbc.Driver 2、主启动类添加注解 SpringBootApplication     MapperScan(com.example.demo.mapper) 3、编写配置类 Getterpublic enum DataSourceKey {     /**     * Order data source key.     */    ORDER,     /**     * Storage data source key.     */    STORAGE,     /**     * Pay data source key.     */    PAY,} public class DynamicDataSourceContextHolder {     private static final ThreadLocalString CONTEXT_HOLDER ThreadLocal.withInitial(DataSourceKey.ORDER::name);     private static ListObject dataSourceKeys new ArrayList();     public static void setDataSourceKey(DataSourceKey key) {         CONTEXT_HOLDER.set(key.name());    }     public static String getDataSourceKey() {         return CONTEXT_HOLDER.get();    }     public static void clearDataSourceKey() {         CONTEXT_HOLDER.remove();    }     public static ListObject getDataSourceKeys() {         return dataSourceKeys;    }} public class DynamicRoutingDataSource extends AbstractRoutingDataSource {     Override     protected Object determineCurrentLookupKey() {         //log.info(当前数据源 [{}], DynamicDataSourceContextHolder.getDataSourceKey());        return DynamicDataSourceContextHolder.getDataSourceKey();    }} Configurationpublic class DataSourceProxyConfig {     Bean(originOrder)     ConfigurationProperties(prefix spring.datasource.order)     public DataSource dataSourceMaster() {         return new DruidDataSource();    }     Bean(originStorage)     ConfigurationProperties(prefix spring.datasource.storage)     public DataSource dataSourceStorage() {         return new DruidDataSource();    }     Bean(originPay)     ConfigurationProperties(prefix spring.datasource.pay)     public DataSource dataSourcePay() {         return new DruidDataSource();    }     Bean(name order)     public DataSourceProxy masterDataSourceProxy(Qualifier(originOrder) DataSource dataSource) {         return new DataSourceProxy(dataSource);    }     Bean(name storage)     public DataSourceProxy storageDataSourceProxy(Qualifier(originStorage) DataSource dataSource) {         return new DataSourceProxy(dataSource);    }     Bean(name pay)     public DataSourceProxy payDataSourceProxy(Qualifier(originPay) DataSource dataSource) {         return new DataSourceProxy(dataSource);    }     Bean(dynamicDataSource)     public DataSource dynamicDataSource(Qualifier(order) DataSource dataSourceOrder,                                         Qualifier(storage) DataSource dataSourceStorage,                                         Qualifier(pay) DataSource dataSourcePay) {        DynamicRoutingDataSource dynamicRoutingDataSource new DynamicRoutingDataSource();        MapObject, Object dataSourceMap new HashMap(3);        dataSourceMap.put(DataSourceKey.ORDER.name(), dataSourceOrder);        dataSourceMap.put(DataSourceKey.STORAGE.name(), dataSourceStorage);        dataSourceMap.put(DataSourceKey.PAY.name(), dataSourcePay);        dynamicRoutingDataSource.setDefaultTargetDataSource(dataSourceOrder);        dynamicRoutingDataSource.setTargetDataSources(dataSourceMap);        DynamicDataSourceContextHolder.getDataSourceKeys().addAll(dataSourceMap.keySet());         return dynamicRoutingDataSource;    }     Bean    ConfigurationProperties(prefix mybatis-plus)  // MybatisSqlSessionFactoryBean中有各种MybatisPlus的配置属性(globalConfig、mapperLocations} 而SqlSessionFactoryBean中则是mybatis的各种配置属性(typeAlies、mapperLocations)      public MybatisSqlSessionFactoryBean sqlSessionFactoryBean(Qualifier(dynamicDataSource) DataSource dataSource) {         // 这里用 MybatisSqlSessionFactoryBean 代替了 SqlSessionFactoryBean否则 MyBatisPlus 不会生效        MybatisSqlSessionFactoryBean mybatisSqlSessionFactoryBean new MybatisSqlSessionFactoryBean();        mybatisSqlSessionFactoryBean.setDataSource(dataSource);         return mybatisSqlSessionFactoryBean;    }} 调用切换数据源 GlobalTransactionalOverridepublic OperationResponse placeOrder(PlaceOrderRequestVO placeOrderRequestVO) throws Exception {     DynamicDataSourceContextHolder.setDataSourceKey(DataSourceKey.ORDER);//切换数据源    Integer amount 1;    Integer price placeOrderRequestVO.getPrice();    Order order Order.builder().build();    Integer saveOrderRecord orderDao.insert(order);     // 扣减库存    boolean operationStorageResult storageService.reduceStock(placeOrderRequestVO.getProductId(), amount);     // 扣减余额    boolean operationBalanceResult payService.reduceBalance(placeOrderRequestVO.getUserId(), price);     DynamicDataSourceContextHolder.setDataSourceKey(DataSourceKey.ORDER);//切换数据源    order.setStatus(OrderStatus.SUCCESS);    Integer updateOrderRecord orderDao.updateById(order);     return success(operationStorageResult operationBalanceResult);} 项目启动报错Failed to configure a DataSource: url attribute is not specified and no embedded datasource could be configured 原因导入spring-mybatis依赖后springboot启动时会自动加载数据源由于dataSource配置成多数据源加载不到spring.datasource.url故而报错。 解决1、主启动类添加SpringBootApplication(exclude DataSourceAutoConfiguration.class) 2、若上面配置还是无法解决可以配置一个默认数据源让其启动时加载(不影响,会被多数据源切换时覆盖的)spring.datasource.url 额外 SqlSessionFactory factorynew SqlSessionFactoryBuilder().build(in); SqlSession sqlSessionfactory.openSession(); //sqlSession就是用来操作sql语句的 使用 MyBatis-Spring 之后, 会使用SqlSessionFactoryBean来代替SqlSessionFactoryBuilder创建SqlSessionFactory MybatisPlus需要使用MybatisSqlSessionFactoryBean。
http://www.dnsts.com.cn/news/77942.html

相关文章:

  • 手机app制作网站用什么软件php和mysql做租车网站
  • 网站建设账户搭建设计有哪些网站
  • 电子商务网站建设教程哪个公司的网络比较稳定
  • 聊城网站建设有限公司得物app官方下载安装
  • 自动化设备技术支持东莞网站建设租电信网站服务器
  • 长沙网站开发哪家好app是什么软件
  • 广西网站建设-好发信息网盐城网站建设要多少钱
  • 网站开发平台开发公司网站推广双鼎
  • asp net做网站苏州网站建设外包
  • 威海市建设局官方网站wordpress前缀
  • 怎么样建设一个电影网站视频天津百度分公司
  • 多城市分站网站建设网络公司的经营范围有哪些
  • 十大创意网站线上引流线下推广方案
  • jsp网站开发的mvc俄罗斯免费网站推广
  • 莱芜网站建设怎么样班级网站建设首页报告
  • 网站建设云南如何建国际商城网站
  • 福州网站建设兼职泉州网站制作
  • 海口房产网站建设网店设计方案范文
  • 网站改版 升级的目的是什么做手机网站多少钱
  • 做网站的投入创新创业项目计划书
  • 网站上线详细步骤企业直招平台
  • 高站网站建设国际化域名
  • 网站开发文档需求模板iis5.1新建网站
  • 成都网站建设开发价格南京网站制作公司排名
  • 新乡手机网站建设哪家好it外包合同
  • 做网站广告怎么做在线网页截图工具
  • thinkphp做网站企业网站内容运营
  • 取消网站的通知书中国已封城市名单
  • 公司网站可以免费建吗南阳专业网站建设
  • 通辽网站制作公司基于android的app的设计与开发