MyBatis整合多数据源

news/2024/9/9 13:44:28

基础环境

SpringBoot : 3.0.0
Java: jdk-17.0.5
Maven: 3.6.1

引入相关jar

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.0.0-SNAPSHOT</version><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.giser</groupId><artifactId>gis-java-mp</artifactId><version>0.0.1-SNAPSHOT</version><name>gis-java-mp</name><description>Demo project for Spring Boot</description><properties><java.version>17</java.version></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-boot-starter</artifactId><version>3.5.3</version><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></exclusion></exclusions></dependency><dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.6.1</version><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-aop</artifactId></exclusion><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId></exclusion></exclusions></dependency><!-- https://mvnrepository.com/artifact/com.baomidou/mybatis-plus-generator --><dependency><groupId>com.baomidou</groupId><artifactId>mybatis-plus-generator</artifactId><version>3.5.3</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-jdbc</artifactId><version>2.1.3.RELEASE</version></dependency><dependency><groupId>mysql</groupId><artifactId>mysql-connector-java</artifactId><version>8.0.16</version></dependency><!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-freemarker --><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId><version>3.1.5</version></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-autoconfigure</artifactId><version>3.0.0</version></dependency></dependencies><build><finalName>gis-mp</finalName><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId><version>2.5.4</version><configuration><mainClass>com.giser.mp.GisJavaMpApplicationTests</mainClass></configuration></plugin></plugins></build></project>

数据源等配置

server:port: 9999servlet:context-path: /encoding:charset: UTF-8spring:datasource:params: useSSL=false&useUnicode=true&characterEncoding=UTF-8&autoReconnect=true&allowMultiQueries=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true&serverTimezone=GMT%2B8dynamic:primary: masterstrict: falsedatasource:master:url: jdbc:mysql://ip:port/dbname?${spring.datasource.params}username: dbusernamepassword: dbpasswordslave:url: jdbc:mysql://ip:port/dbname?${spring.datasource.params}username: dbusernamepassword: dbpasswordhikari:max-lifetime: 18000connection-timeout: 10000idle-timeout: 3600000min-idle: 4max-pool-size: 12

https://www.xjx100.cn/news/3092491.html

相关文章

计算机显示msvcp140.dll丢失的解决方法,实测有效的5个方法分享

在日常的电脑操作中&#xff0c;常常遭遇某些错误讯息&#xff0c;如“缺少xxx.dll文件”&#xff0c;这些dll文件即为动态链接库文件&#xff0c;内含诸多可执行的程序码及数据。当启动某款应用时&#xff0c;系统将会自动调用与其相关的dll文件&#xff0c;其中msvcp140.dll便…

使用sonar对webgoat进行静态扫描

安装sonar并配置 docker安装sonarqube&#xff0c;sonarQube静态代码扫描 - Joson6350 - 博客园 (cnblogs.com) 对webgoat进行sonar扫描 扫描结果 bugs Change this condition so that it does not always evaluate to "false" 意思是这里的else if语句不会执行…

kafka权限认证 topic权限认证 权限动态认证-亲测成功

kafka权限认证 topic权限认证 权限动态认证-亲测成功 kafka动态认证 自定义认证 安全认证-亲测成功 MacBook Linux安装Kafka Linux解压安装Kafka 介绍 1、Kafka的权限分类 身份认证&#xff08;Authentication&#xff09;&#xff1a;对client 与服务器的连接进行身份认证…

C语言进制转换(1112:进制转换(函数专题))

题目描述 输入一个十进制整数n&#xff0c;输出对应的二进制整数。常用的转换方法为“除2取余&#xff0c;倒序排列”。将一个十进制数除以2&#xff0c;得到余数和商&#xff0c;将得到的商再除以2&#xff0c;依次类推&#xff0c;直到商等于0为止&#xff0c;倒取除得的余数…

78基于matlab的BiLSTM分类算法,输出迭代曲线,测试集和训练集分类结果和混淆矩阵

基于matlab的BiLSTM分类算法&#xff0c;输出迭代曲线&#xff0c;测试集和训练集分类结果和混淆矩阵&#xff0c;程序有详细注释&#xff0c;数据可更换自己的&#xff0c;程序已调通&#xff0c;可直接运行。

谈谈你对mvc和mvvm的理解

MVC和MVVM是软件开发中两种常见的架构模式&#xff0c;各自有不同的优缺点。 MVC&#xff08;Model-View-Controller&#xff09;是一种经典的架构模式&#xff0c;将应用程序分为三个部分&#xff1a;模型&#xff08;Model&#xff09;、视图&#xff08;View&#xff09;和…

[计算机网络实验]头歌 实验二 以太网帧、IP报文分析

第1关&#xff1a;Wireshark基本使用入门 【实验目的】 1、掌握wireshark工具的基本使用方法 【实验环境】 1、头歌基于Linux的虚拟机桌面系统 2、网络报文分析工具wireshark 3、浏览器firefox 【本地主机、平台虚拟机之间数据传递】 1、文本的复制与粘贴 操作入口&…

宇视科技通过stm32叠加字符串

void sendtoYskj(uint8_t *cameraIp,uint16_t cameraSrcPort,uint16_t cameraDstPort,uint8_t *userName,uint8_t *pwd,uint8_t lineNum,int camNo)//宇视科技 { int flag = 1; int sock = -1,connected; int send_data_len; int recv_data_len; //char str…