中文亚洲精品无码_熟女乱子伦免费_人人超碰人人爱国产_亚洲熟妇女综合网

當(dāng)前位置: 首頁 > news >正文

郵箱網(wǎng)址查詢百度刷排名seo

郵箱網(wǎng)址查詢,百度刷排名seo,青島昌隆文具網(wǎng)站是哪家公司做的,大型旅行社自建網(wǎng)站配置多數(shù)據(jù)源 模擬多庫場景 適用于多種場景: 多庫(操作的表分布在不同數(shù)據(jù)庫當(dāng)中),讀寫分離(有的數(shù)據(jù)庫負(fù)責(zé)查詢的功能,有的數(shù)據(jù)庫負(fù)責(zé)增刪該的功能),一主多從,混合模式等 第一步: 模擬多庫,在mybatis_plus數(shù)據(jù)庫中創(chuàng)建user表,在mybatis_plus_1數(shù)據(jù)庫中創(chuàng)建product表 --創(chuàng)建…

配置多數(shù)據(jù)源

模擬多庫場景

適用于多種場景: 多庫(操作的表分布在不同數(shù)據(jù)庫當(dāng)中),讀寫分離(有的數(shù)據(jù)庫負(fù)責(zé)查詢的功能,有的數(shù)據(jù)庫負(fù)責(zé)增刪該的功能),一主多從,混合模式等

第一步: 模擬多庫,在mybatis_plus數(shù)據(jù)庫中創(chuàng)建user表,在mybatis_plus_1數(shù)據(jù)庫中創(chuàng)建product表

--創(chuàng)建mybatis_plus數(shù)據(jù)庫
CREATE DATABASE `mybatis_plus` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
use `mybatis_plus`;
--創(chuàng)建user表
CREATE TABLE `t_user` (`id` bigint(20) NOT NULL COMMENT '主鍵ID',`name` varchar(30) DEFAULT NULL COMMENT '姓名',`age` int(11) DEFAULT NULL COMMENT '年齡',`email` varchar(50) DEFAULT NULL COMMENT '郵箱',PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
--向user表中插入數(shù)據(jù)
INSERT INTO t_user (id, name, age, email) VALUES
(1, 'Jone', 18, 'test1@baomidou.com'),
(2, 'Jack', 20, 'test2@baomidou.com'),
(3, 'Tom', 28, 'test3@baomidou.com'),
(4, 'Sandy', 21, 'test4@baomidou.com'),
(5, 'Billie', 24, 'test5@baomidou.com');
--創(chuàng)建mybatis_plus_1數(shù)據(jù)庫
CREATE DATABASE `mybatis_plus_1` /*!40100 DEFAULT CHARACTER SET utf8mb4 */;
use `mybatis_plus_1`;
--創(chuàng)建product表
CREATE TABLE t_product(
id BIGINT(20) NOT NULL COMMENT '主鍵ID',
name VARCHAR(30) NULL DEFAULT NULL COMMENT '商品名稱',
price INT(11) DEFAULT 0 COMMENT '價格',
version INT(11) DEFAULT 0 COMMENT '樂觀鎖版本號',
PRIMARY KEY (id)
);
--向product表插入數(shù)據(jù)
INSERT INTO t_product (id, NAME, price) VALUES (1, '外星人筆記本', 100);

第二步:在pom.xml文件中引入多數(shù)據(jù)源使用的依賴

<!--配置多數(shù)據(jù)源需要使用的依賴-->
<dependency><groupId>com.baomidou</groupId><artifactId>dynamic-datasource-spring-boot-starter</artifactId><version>3.5.0</version>
</dependency>

第三步: 在appilcation.yaml文件中添加配置多數(shù)據(jù)源的配置選項(xiàng)

spring:# 配置數(shù)據(jù)源信息datasource:dynamic:# 設(shè)置默認(rèn)的數(shù)據(jù)源或者數(shù)據(jù)源組,默認(rèn)值即為masterprimary: master# 嚴(yán)格匹配數(shù)據(jù)源(默認(rèn)false),true表示如果未匹配到指定數(shù)據(jù)源時拋異常,false表示如果未匹配到指定的數(shù)據(jù)源就使用默認(rèn)的數(shù)據(jù)源strict: falsedatasource:master: # 默認(rèn)數(shù)據(jù)源url: jdbc:mysql://localhost:3306/mybatis_plus?characterEncoding=utf-8&useSSL=falsedriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: 123456slave_1: # 其他數(shù)據(jù)源url: jdbc:mysql://localhost:3306/mybatis_plus_1?characterEncoding=utf-8&useSSL=falsedriver-class-name: com.mysql.cj.jdbc.Driverusername: rootpassword: 123456

第四步: 創(chuàng)建實(shí)體類封裝表中查詢的數(shù)據(jù)

//封裝用戶信息的實(shí)體類
@Data
@TableName("t_user")
public class User {private Integer id;private String name;private Integer age;private String email;
}
//封裝產(chǎn)品信息的實(shí)體類
@Data
@TableName("t_product")
public class Product {private Integer id;private String name;private Integer price;private Integer version;
}

第五步: 編寫User和Product對應(yīng)的mapper接口和service接口

@Repository
public interface ProductMapper extends BaseMapper<Product> {
}@Repository
public interface UserMapper extends BaseMapper<User> {
}public interface UserService extends IService<User> {}public interface ProductService extends IService<Product> {}

第六步: 創(chuàng)建User和Product實(shí)體類對應(yīng)的service接口的實(shí)現(xiàn)類,使用@DS注解指定當(dāng)前類或方法要操作的數(shù)據(jù)源

  • @Ds注解使用在方法上或類上(使用在類上表示類中所有的方法默認(rèn)都有該注解)
  • @Ds注解在類和方法上同時存在則遵循就近原則,方法上指定操作的數(shù)據(jù)源優(yōu)先于類上指定操作的數(shù)據(jù)源
注解結(jié)果
沒有@DS注解操作默認(rèn)的數(shù)據(jù)源
@DS(“dsName”)dsName為要操作的數(shù)據(jù)源名稱
@Service
@DS("master") //t_user表在master數(shù)據(jù)源當(dāng)中
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implementsUserService {
}@Service
@DS("slave_1")//t_product表在slave_1數(shù)據(jù)源當(dāng)中
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {
}

第七步: 編寫Spring Boot主程序的啟動類

@SpringBootApplication
@MapperScan("com.atguigu.mybatisplus.mapper")// 掃描mapper接口所在的包
public class MybatisPlusDatasourceApplication {public static void main(String[] args) {SpringApplication.run(MybatisPlusDatasourceApplication.class, args);}
}

第八步: 由于t_user表和t_product在兩個不同的數(shù)據(jù)庫(數(shù)據(jù)源)中,如果通過一個測試方法可以分別獲取到用戶數(shù)據(jù)與商品數(shù)據(jù)成功說明多庫模擬成功

@SpringBootTest
public class MybatisPlusDatasourceApplicationTests {@Autowiredprivate UserService userService;@Autowiredprivate ProductService productService;@Testpublic void testDynamicDataSource(){// 輸出查詢出來的對象System.out.println(userService.getById(1));System.out.println(productService.getById(1));}
}

模擬讀寫分離

實(shí)現(xiàn)讀寫分離的效果

  • 寫操作: 增刪改操作的方法加上@DS注解指定操作主庫數(shù)據(jù)源,因?yàn)橹挥兄鲾?shù)據(jù)源才可以把更新的操作同步到從數(shù)據(jù)源
  • 讀操作: 查詢操作的方法指定操作從庫數(shù)據(jù)源
http://www.risenshineclean.com/news/2255.html

相關(guān)文章:

  • 八方資源網(wǎng)做網(wǎng)站優(yōu)化怎么樣群排名優(yōu)化軟件
  • 如何做配音網(wǎng)站問卷調(diào)查網(wǎng)站
  • 六盤水南寧網(wǎng)站建設(shè)seo服務(wù)靠譜嗎
  • 網(wǎng)站后臺模板html優(yōu)化大師優(yōu)化項(xiàng)目有
  • 動態(tài)網(wǎng)站系統(tǒng)的5個組成部分代哥seo
  • wordpress資訊站臨沂seo整站優(yōu)化廠家
  • 杭州富陽做網(wǎng)站百度云網(wǎng)盤資源搜索
  • 給別人做網(wǎng)站去掉版權(quán)日本比分預(yù)測
  • 迪奧生物做圖網(wǎng)站寧波seo優(yōu)化公司排名
  • 做網(wǎng)站怎么融資2345網(wǎng)址導(dǎo)航大全
  • 自助建站亞馬遜關(guān)鍵詞排名查詢工具
  • 給自己的網(wǎng)站做鏡像網(wǎng)站外貿(mào)網(wǎng)站模板
  • 哪家網(wǎng)站建設(shè)服務(wù)好網(wǎng)絡(luò)廣告策劃與制作
  • 網(wǎng)站建設(shè)公司計劃書關(guān)鍵詞排名優(yōu)化公司哪家好
  • 電商網(wǎng)頁模板優(yōu)化快速排序
  • 上海設(shè)計網(wǎng)站開發(fā)深圳網(wǎng)站關(guān)鍵詞優(yōu)化推廣
  • 自己做視頻網(wǎng)站 在優(yōu)酷推廣競價推廣運(yùn)營
  • 上海做網(wǎng)站 公司qq推廣官網(wǎng)
  • 江蘇外貿(mào)型網(wǎng)站制作搜索引擎原理
  • 大連做網(wǎng)站哪家服務(wù)好seo課程培訓(xùn)中心
  • 曲靖網(wǎng)站制作今日新聞?wù)?/a>
  • 地方門戶網(wǎng)站制作蘇州網(wǎng)站制作推廣
  • 北京建網(wǎng)站公司價格關(guān)鍵字排名查詢
  • 建設(shè)工程施工包括哪些工程深圳純手工seo
  • 松江微網(wǎng)站建設(shè)重慶seo技術(shù)分享
  • .tel域名不可以做網(wǎng)站域名嗎?業(yè)務(wù)網(wǎng)站制作
  • 團(tuán)購做的好的網(wǎng)站有哪些互聯(lián)網(wǎng)去哪里學(xué)
  • 網(wǎng)頁設(shè)計教程誰的好西安市seo排名按天優(yōu)化
  • 現(xiàn)在網(wǎng)站建設(shè)怎么收費(fèi)嘉興seo外包平臺
  • 成品網(wǎng)站源碼1688體驗(yàn)區(qū)免費(fèi)網(wǎng)絡(luò)推廣平臺有哪些