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

寄生虫seo教程北京官网优化公司

寄生虫seo教程,北京官网优化公司,java做网站用到哪些技术,绍兴手机网站建设一、背景 在SpringBoot Mybatis 项目中&#xff0c;需要连接 多个数据源&#xff0c;连接多个数据库&#xff0c;需要连接一个MySQL数据库和一个Oracle数据库和一个Redis 二、依赖 pom.xml <dependencies><dependency><groupId>org.springframework.boot&l…

 一、背景

在SpringBoot Mybatis 项目中,需要连接 多个数据源,连接多个数据库,需要连接一个MySQL数据库和一个Oracle数据库和一个Redis

二、依赖 pom.xml

 <dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><!-- MySQL --><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.26</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></dependency><dependency><groupId>org.mybatis.spring.boot</groupId><artifactId>mybatis-spring-boot-starter</artifactId><version>1.3.2</version></dependency><!-- Oracle --><dependency><groupId>com.oracle.database.jdbc</groupId><artifactId>ojdbc8</artifactId><version>19.8.0.0</version></dependency><!-- Redis --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.4.4</version></dependency><!-- lombok --><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>1.18.16</version><scope>provided</scope></dependency><dependency><groupId>javax.persistence</groupId><artifactId>javax.persistence-api</artifactId><version>2.2</version></dependency><!--swagger2--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version></dependency><!--swagger-ui--><dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version></dependency><!-- https://mvnrepository.com/artifact/cn.easyproject/orai18n --><dependency><groupId>cn.easyproject</groupId><artifactId>orai18n</artifactId><version>12.1.0.2.0</version></dependency></dependencies>

三、项目结构

四、application.yml

spring.datasource.url数据库的JDBC URL

spring.datasource.jdbc-url用来重写自定义连接池

Hikari没有url属性,但是有jdbcUrl属性,在这中情况下必须使用jdbc_url

server:port: 8080spring:datasource:primary:jdbc-url: jdbc:mysql://localhost:3306/database_nameusername: rootpassword: 123456driver-class-name: com.mysql.cj.jdbc.Driversecondary:jdbc-url: jdbc:oracle:thin:@localhost:1521/ORCLusername: rootpassword: 123456driver-class-name: oracle.jdbc.driver.OracleDriver    

五、MySQL配置类

MysqlDataSourceConfig

使用注解@Primary配置默认数据源

package com.example.multipledata.config.mysqlconfig;import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
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 org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration
@MapperScan(basePackages = MysqlDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "mysqlSqlSessionFactory")
public class MysqlDataSourceConfig {static final String PACKAGE = "com.example.multipledata.mapper.mysqlmapper";static final String MAPPER_LOCATION = "classpath*:mapper/mysqlmapper/*.xml";@Primary@Bean(name = "mysqlDataSource")@ConfigurationProperties(prefix = "spring.datasource.primary")public DataSource mysqlDataSource() {return DataSourceBuilder.create().build();}@Primary@Bean(name = "mysqlTransactionManager")public DataSourceTransactionManager mysqlTransactionManager() {return new DataSourceTransactionManager((mysqlDataSource()));}@Primary@Bean(name = "mysqlSqlSessionFactory")public SqlSessionFactory mysqlSqlSessionFactory(@Qualifier("mysqlDataSource") DataSource mysqlDatasource) throws Exception {final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();sessionFactory.setDataSource(mysqlDatasource);sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(MysqlDataSourceConfig.MAPPER_LOCATION));return sessionFactory.getObject();}
}

六、Oracle配置类

OracleDataSourceConfig

package com.example.multipledata.config.oracleconfig;import org.apache.ibatis.session.SqlSessionFactory;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.beans.factory.annotation.Qualifier;
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.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;import javax.sql.DataSource;@Configuration
@MapperScan(basePackages = OracleDataSourceConfig.PACKAGE, sqlSessionFactoryRef = "oracleSqlSessionFactory")
public class OracleDataSourceConfig {static final String PACKAGE = "com.example.multipledata.mapper.oraclemapper";static final String MAPPER_LOCATION = "classpath*:mapper/oraclemapper/*.xml";@Bean(name = "oracleDataSource")@ConfigurationProperties(prefix = "spring.datasource.secondary")public DataSource oracleDataSource() {return DataSourceBuilder.create().build();}@Bean(name = "oracleTransactionManager")public DataSourceTransactionManager oracleTransactionManager() {return new DataSourceTransactionManager(oracleDataSource());}@Bean(name = "oracleSqlSessionFactory")public SqlSessionFactory oracleSqlSessionFactory(@Qualifier("oracleDataSource") DataSource oracleDataSource) throws Exception {final SqlSessionFactoryBean sessionFactory = new SqlSessionFactoryBean();sessionFactory.setDataSource(oracleDataSource);sessionFactory.setMapperLocations(new PathMatchingResourcePatternResolver().getResources(OracleDataSourceConfig.MAPPER_LOCATION));return sessionFactory.getObject();}
}

原文地址:

https://www.cnblogs.com/windy-xmwh/p/14748567.html

七、增加Redis连接

注意,我的Redis连接,使用了密码

7.1 新增依赖 pom.xml

pom.xml

        <!-- Redis --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-data-redis</artifactId><version>2.4.4</version></dependency><dependency><groupId>io.lettuce</groupId><artifactId>lettuce-core</artifactId></dependency>

7.2 配置Redis连接  application.yml

  spring:redis:host: hostport: 6379password: 1

7.3 Redis 配置文件 RedisConfig

在config目录下,新增RedisConfig文件

package com.example.kyjjserver.config;import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.StringRedisSerializer;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;@Configuration
public class RedisConfig {@Value("${spring.redis.host}")private String redisHost;@Value("${spring.redis.port}")private int redisPort;@Value("${spring.redis.password}")private String redisPassword;@Beanpublic RedisConnectionFactory redisConnectionFactory() {LettuceConnectionFactory lettuceConnectionFactory = new LettuceConnectionFactory(redisHost, redisPort);lettuceConnectionFactory.setPassword(redisPassword);return lettuceConnectionFactory;}@Beanpublic RedisTemplate<String, Object> redisTemplate(RedisConnectionFactory redisConnectionFactory) {RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();redisTemplate.setConnectionFactory(redisConnectionFactory);redisTemplate.setKeySerializer(new StringRedisSerializer());redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());redisTemplate.setHashKeySerializer(new StringRedisSerializer());redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());redisTemplate.afterPropertiesSet();return redisTemplate;}
}

7.4 操作Redis

7.4.1 封装操作方法

在service目录下,新增RedisService文件

package com.example.kyjjserver.service;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;import java.util.Set;@Service
public class RedisService {private final RedisTemplate<String, Object> redisTemplate;@Autowiredpublic RedisService(RedisTemplate<String, Object> redisTemplate) {this.redisTemplate = redisTemplate;}public void deleteData(String key) {redisTemplate.delete(key);}public void deleteDataAll(String pattern) {Set<String> keys = redisTemplate.keys("*" + pattern + "*");if (keys != null) {redisTemplate.delete(keys);}}
}

7.4.2 调用方法,操作Redis库

1、注入

2、调用

@Component
public class DeleteRedisInfo {@Autowiredprivate RedisService redisService;@Transactionalpublic AAA deleteUser(xxx xxx){// 删除手机号redisService.deleteDataAll(xxx);return xxx;}
}

http://www.rdtb.cn/news/18164.html

相关文章:

  • 沈阳建立网站中国十大小说网站排名
  • 自己主机做网站服务器小红书推广费用一般多少
  • 广州市住房和城乡建设厅网站武汉seo全网营销
  • the7企业中 英文wordpress模板宁波网络推广优化方案
  • 做网站运营用什么软件seo排名优化公司哪家好
  • 广州vi设计平面广告公司网站为什么要seo?
  • 上饶市建设局有什么网站高端企业网站定制公司
  • dw网站轮播效果怎么做设计公司企业网站
  • 网站制作一条龙免费推广平台哪些比较好
  • 怎样做微信挂机平台网站如何获取永久免费域名
  • wordpress 修改头像大小重庆seo招聘
  • 贴心网络推广方法关键词优化推广排名多少钱
  • iis 会影响 网站 速度百度入口提交
  • 外贸公司名字大全seo运营学校
  • 网页制作与网站建设 自考湖南网站推广
  • wordpress的ip有什么用网站seo完整seo优化方案
  • 网站自动登录怎么做宣传网站有哪些
  • 网域高科学校网站管理系统漏洞seo综合查询网站源码
  • wp建站系统产品推广营销
  • wordpress 指定页面网站关键词怎么优化到首页
  • 浙江商会网站建设策划方案最新app推广
  • 网站建设海报素材优化网站的步骤
  • 哪些网站做机票酒店有优势培训机构哪家最好
  • 物流公司做网站需求seo结算系统
  • 广告公司微网站建设自己建网站详细流程
  • 淄博哪有做网站的互联网销售怎么做
  • 在网站上使用特殊字体百度如何优化
  • 做网站还要买服务器吗每日新闻简报
  • 网站后期维护怎么做口碑营销的产品
  • web 开发 网站开发推广什么软件可以长期赚钱