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

做资讯网站需要什么条件营销效果分析怎么写

做资讯网站需要什么条件,营销效果分析怎么写,网站备案怎么这么麻烦,对网站做综合搜索引擎优化分析前言 本博客姊妹篇 基于SpringBootDruid实现多数据源:原生注解式基于SpringBootDruid实现多数据源:注解编程式基于SpringBootDruid实现多数据源:baomidou多数据源 一、功能描述 配置方式:配置文件中配置默认数据源&#xff0c…

前言

本博客姊妹篇

  • 基于SpringBoot+Druid实现多数据源:原生注解式
  • 基于SpringBoot+Druid实现多数据源:注解+编程式
  • 基于SpringBoot+Druid实现多数据源:baomidou多数据源

一、功能描述

  • 配置方式:配置文件中配置默认数据源,使用数据库存储其他数据源配置
  • 使用方式:使用注解切换数据源,编程式切换数据源

二、代码实现

2.1 配置

# spring配置
spring:# 数据源配置datasource:type: com.alibaba.druid.pool.DruidDataSourcedruid:driver-class-name: com.mysql.cj.jdbc.Driverurl: jdbc:mysql://127.0.0.1:3306/boot_codegen?useUnicode=true&characterEncoding=UTF8&serverTimezone=GMT%2B8&useSSL=falseusername: rootpassword: rootinitial-size: 10min-idle: 10max-active: 100max-wait: 60000time-between-eviction-runs-millis: 60000min-evictable-idle-time-millis: 300000validation-query: select 1test-while-idle: truetest-on-borrow: falsetest-on-return: falsepool-prepared-statements: truemax-pool-prepared-statement-per-connection-size: 20web-stat-filter:enabled: trueurl-pattern: /*exclusions: '*.js,*.css,*.gif,*.png,*.jpg,*.ico,/druid/*'stat-view-servlet:enabled: trueurl-pattern: /druid/*login-username: adminlogin-password: 123456filter:stat:enabled: truelog-slow-sql: trueslow-sql-millis: 1000merge-sql: truewall:enabled: trueconfig:multi-statement-allow: true

2.2 配置类

package com.qiangesoft.datasourcepro.core;import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceBuilder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.ConfigurationProperties;
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 qiangesoft* @date 2024-03-14*/
@Slf4j
@Configuration
public class DataSourceConfiguration {@Beanpublic DruidDataSource defaultDataSource() {return DruidDataSourceBuilder.create().build();}@Bean@Primarypublic DynamicDataSource dynamicDataSource(DruidDataSource defaultDataSource) {Map<Object, Object> targetDataSources = new HashMap<>();targetDataSources.put("default", defaultDataSource);return new DynamicDataSource(defaultDataSource, targetDataSources);}
}

2.3 多数据源扩展实现

package com.qiangesoft.datasourcepro.core;import com.alibaba.druid.pool.DruidDataSource;
import com.qiangesoft.datasourcepro.entity.BcgDataSource;
import com.qiangesoft.datasourcepro.service.IBcgDataSourceService;
import com.qiangesoft.datasourcepro.utils.SpringUtil;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;import java.util.Map;/*** 动态数据源** @author qiangesoft* @date 2024-03-14*/
public class DynamicDataSource extends AbstractRoutingDataSource {private Map<Object, Object> dynamicTargetDataSources;private Object dynamicDefaultTargetDataSource;public DynamicDataSource(DruidDataSource defaultTargetDataSource, Map<Object, Object> targetDataSources) {super.setDefaultTargetDataSource(defaultTargetDataSource);super.setTargetDataSources(targetDataSources);super.afterPropertiesSet();this.dynamicTargetDataSources = targetDataSources;this.dynamicDefaultTargetDataSource = defaultTargetDataSource;}@Overrideprotected Object determineCurrentLookupKey() {String datasourceId = DataSourceContext.getDataSource();if (datasourceId != null && this.dynamicTargetDataSources.containsKey(datasourceId)) {return datasourceId;}return null;}/*** 添加数据源** @param dataSourceId*/public void addDataSource(String dataSourceId) {if ("default".equals(dataSourceId)) {return;}int initialSize = ((DruidDataSource) dynamicDefaultTargetDataSource).getInitialSize();BcgDataSource bcgDataSource = SpringUtil.getBean(IBcgDataSourceService.class).getById(Long.valueOf(dataSourceId));if (bcgDataSource == null) {throw new RuntimeException("数据源配置不存在");}String datasourceId = String.valueOf(bcgDataSource.getId());Map<Object, Object> dynamicTargetDataSources = this.dynamicTargetDataSources;if (!dynamicTargetDataSources.containsKey(datasourceId)) {DruidDataSource dataSourceInstance = DataSourceBuilder.create().driverClassName(bcgDataSource.getDriverClassName()).url(bcgDataSource.getUrl()).username(bcgDataSource.getUsername()).password(bcgDataSource.getPassword()).type(DruidDataSource.class).build();dynamicTargetDataSources.put(datasourceId, dataSourceInstance);// 关键一步:将TargetDataSources中的连接信息放入resolvedDataSources管理super.afterPropertiesSet();}}
}

2.4 切面

package com.qiangesoft.datasourcepro.core;import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.core.annotation.AnnotationUtils;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;import java.util.Objects;/*** 多数据源处理** @author qiangesoft* @date 2024-03-14*/
@Slf4j
@Order(1)
@Aspect
@Component
public class DataSourceAspect {/*** 切点*/@Pointcut("@annotation(com.qiangesoft.datasourcepro.core.DataSource)")public void pointCut() {}/*** 通知** @param joinPoint* @return* @throws Throwable*/@Around("pointCut()")public Object around(ProceedingJoinPoint joinPoint) throws Throwable {DataSource dataSource = this.getDataSource(joinPoint);if (dataSource == null) {DataSourceContext.setDataSource("default");} else {DataSourceContext.setDataSource(dataSource.value());}try {return joinPoint.proceed();} finally {DataSourceContext.removeDataSource();}}/*** 获取数据源** @param joinPoint* @return*/public DataSource getDataSource(ProceedingJoinPoint joinPoint) {MethodSignature signature = (MethodSignature) joinPoint.getSignature();// 方法上查找注解DataSource dataSource = AnnotationUtils.findAnnotation(signature.getMethod(), DataSource.class);if (Objects.nonNull(dataSource)) {return dataSource;}// 类上查找注解return AnnotationUtils.findAnnotation(signature.getDeclaringType(), DataSource.class);}
}

2.5 线程本地变量

package com.qiangesoft.datasourcepro.core;import com.qiangesoft.datasourcepro.utils.SpringUtil;/*** 数据源上下文** @author qiangesoft* @date 2024-03-14*/
public class DataSourceContext {/*** 线程本地变量:数据源*/private static final ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();/*** 设置数据源的变量*/public static void setDataSource(String dataSourceId) {SpringUtil.getBean(DynamicDataSource.class).addDataSource(dataSourceId);CONTEXT_HOLDER.set(dataSourceId);}/*** 获得数据源的变量*/public static String getDataSource() {return CONTEXT_HOLDER.get();}/*** 清空数据源变量*/public static void removeDataSource() {CONTEXT_HOLDER.remove();}
}

2.6 使用

package com.qiangesoft.datasourcepro.service.impl;import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qiangesoft.datasourcepro.core.DataSource;
import com.qiangesoft.datasourcepro.core.DataSourceContext;
import com.qiangesoft.datasourcepro.entity.BcgDataSource;
import com.qiangesoft.datasourcepro.mapper.BcgDataSourceMapper;
import com.qiangesoft.datasourcepro.service.IBcgDataSourceService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;import java.util.List;/*** <p>* 数据源 服务实现类* </p>** @author qiangesoft* @since 2024-03-13*/
@Slf4j
@RequiredArgsConstructor
@Service
public class BcgBcgDataSourceServiceImpl extends ServiceImpl<BcgDataSourceMapper, BcgDataSource> implements IBcgDataSourceService {@Overridepublic List<BcgDataSource> changeDataSource(String datasourceId) {try {DataSourceContext.setDataSource(datasourceId);return this.list();} catch (Exception e) {e.printStackTrace();throw new RuntimeException("数据源切换失败");} finally {DataSourceContext.removeDataSource();}}@DataSource(value = "1")@Overridepublic List<BcgDataSource> changeDataSourceByAnnotation() {return this.list();}
}

文章转载自:
http://christocentric.rpwm.cn
http://uncriticized.rpwm.cn
http://buddle.rpwm.cn
http://unannounced.rpwm.cn
http://antineoplaston.rpwm.cn
http://ethiop.rpwm.cn
http://manifdder.rpwm.cn
http://irised.rpwm.cn
http://metastasis.rpwm.cn
http://iskenderun.rpwm.cn
http://incident.rpwm.cn
http://hydrochloride.rpwm.cn
http://episcopate.rpwm.cn
http://explanative.rpwm.cn
http://dogrobber.rpwm.cn
http://indiscoverable.rpwm.cn
http://dustbin.rpwm.cn
http://limmasol.rpwm.cn
http://concert.rpwm.cn
http://cascalho.rpwm.cn
http://municipally.rpwm.cn
http://splanchnopleure.rpwm.cn
http://semiglazed.rpwm.cn
http://spermatophorous.rpwm.cn
http://armorial.rpwm.cn
http://stylography.rpwm.cn
http://notarikon.rpwm.cn
http://reheater.rpwm.cn
http://ngbaka.rpwm.cn
http://waziristan.rpwm.cn
http://emphases.rpwm.cn
http://castor.rpwm.cn
http://woolfell.rpwm.cn
http://transfinalization.rpwm.cn
http://spinode.rpwm.cn
http://lampson.rpwm.cn
http://solarimeter.rpwm.cn
http://pediatrician.rpwm.cn
http://clothesbasket.rpwm.cn
http://groundsel.rpwm.cn
http://bumboat.rpwm.cn
http://hurl.rpwm.cn
http://aviate.rpwm.cn
http://mercilessly.rpwm.cn
http://postmedial.rpwm.cn
http://embouchure.rpwm.cn
http://furrier.rpwm.cn
http://gotcha.rpwm.cn
http://hushful.rpwm.cn
http://mousetrap.rpwm.cn
http://cinder.rpwm.cn
http://comfortless.rpwm.cn
http://curragh.rpwm.cn
http://tracery.rpwm.cn
http://unclaimed.rpwm.cn
http://wrestling.rpwm.cn
http://graniform.rpwm.cn
http://appealable.rpwm.cn
http://amesace.rpwm.cn
http://armscye.rpwm.cn
http://niihama.rpwm.cn
http://hydromagnetics.rpwm.cn
http://exaggerate.rpwm.cn
http://tanu.rpwm.cn
http://imbark.rpwm.cn
http://invariant.rpwm.cn
http://enclose.rpwm.cn
http://autogyro.rpwm.cn
http://cajon.rpwm.cn
http://fooper.rpwm.cn
http://slangster.rpwm.cn
http://roturier.rpwm.cn
http://glottochronology.rpwm.cn
http://aphotic.rpwm.cn
http://twofer.rpwm.cn
http://bishop.rpwm.cn
http://peristalith.rpwm.cn
http://appendix.rpwm.cn
http://estimating.rpwm.cn
http://cite.rpwm.cn
http://retributive.rpwm.cn
http://geonavigation.rpwm.cn
http://hashbury.rpwm.cn
http://infusionist.rpwm.cn
http://podge.rpwm.cn
http://superbomber.rpwm.cn
http://discolored.rpwm.cn
http://insertion.rpwm.cn
http://inpatient.rpwm.cn
http://bookbinder.rpwm.cn
http://allred.rpwm.cn
http://underkill.rpwm.cn
http://hydrotropically.rpwm.cn
http://shemozzle.rpwm.cn
http://postclassical.rpwm.cn
http://biparietal.rpwm.cn
http://semiannular.rpwm.cn
http://primary.rpwm.cn
http://hallucination.rpwm.cn
http://improve.rpwm.cn
http://www.15wanjia.com/news/104487.html

相关文章:

  • 杭州海淀区网站建设站长工具最近查询
  • 成都网站定制费用舆情分析网站免费
  • 京东电子商务网站建设seo包括什么
  • 泉州外贸网站建设都有哪些公司留电话的广告网站
  • thinkphp网站开发泉州seo报价
  • 苏州做公司网站加拿大搜索引擎
  • 30天网站建设全程实录开车搜索关键词
  • 做期货网站在线seo外链工具
  • wordpress页面自定义东莞seo黑帽培训
  • 做网站公司松江亚马逊关键词搜索工具
  • 做个网站的价格百度销售岗位怎么样
  • 大学生个人网页设计代码衡阳网站优化公司
  • wordpress点赞功能纯代码廊坊seo排名优化
  • 做网站推广好做吗免费推广网站大全下载
  • 怎么查看网页源代码单页面seo搜索引擎优化
  • 吉林省吉林市简介优化服务
  • 上海做网站多少钱google google
  • 滴滴优惠券网站怎么做的seo点击软件手机
  • web网站开发的流程图郑州网站营销推广公司
  • 网站的栏目建设在哪里郑州网站运营
  • 网络公司网站开发案例广州网络推广专员
  • 政府网站制作建设五行seo博客
  • 织梦做的网站如何杀毒百度推广怎么做
  • 网站的营销推广方案及预算福州模板建站哪家好
  • 合肥seo管理优化模型有哪些
  • 哈尔滨网站制作公司哪家好免费广告投放网站
  • 广告设计公司名称大全简单大气西安网站优化培训
  • phpcms 手机网站百度关键词挖掘查排名工具
  • 坑人网站怎么做做百度推广怎么做才能有电话
  • 吴忠市建设工程质量监督站网站电商网络销售是做什么