国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu)

這篇具有很好參考價(jià)值的文章主要介紹了spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu)。希望對(duì)大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請(qǐng)大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問(wèn)。

spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu)

##關(guān)于window mysql主從搭建簡(jiǎn)單教程

傳送門?window mysql5.7 搭建主從同步環(huán)境-CSDN博客

##父pom.xml

<?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 http://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>2.2.2.RELEASE</version>
    </parent>
    <groupId>com.yym</groupId>
    <artifactId>yympro</artifactId>
    <version>1.0</version>
    <packaging>pom</packaging>


</project>

##模塊pom.xml

<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <parent>
    <groupId>com.yym</groupId>
    <artifactId>yympro</artifactId>
    <version>1.0</version>
  </parent>
  <groupId>com.yym</groupId>
  <artifactId>service</artifactId>
  <version>1.0</version>
  <packaging>jar</packaging>

  <name>service</name>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <maven.compiler.source>11</maven.compiler.source>
    <maven.compiler.target>11</maven.compiler.target>
    <alibaba-druid>1.1.22</alibaba-druid>
    <dynamic-datasource-spring-boot-starter.version>3.1.1</dynamic-datasource-spring-boot-starter.version>
    <mybatis-plus-boot-starter>3.3.2</mybatis-plus-boot-starter>
    <shardingsphere>4.1.1</shardingsphere>
  </properties>

  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.11</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter</artifactId>
    </dependency>
    <dependency>
      <groupId>org.springframework.boot</groupId>
      <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>${alibaba-druid}</version>
    </dependency>
    <dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>mybatis-plus-boot-starter</artifactId>
      <version>${mybatis-plus-boot-starter}</version>
    </dependency>
    <!--<dependency>
      <groupId>com.baomidou</groupId>
      <artifactId>dynamic-datasource-spring-boot-starter</artifactId>
      <version>${dynamic-datasource-spring-boot-starter.version}</version>
    </dependency>-->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
    </dependency>
    <dependency>
      <groupId>org.apache.shardingsphere</groupId>
      <artifactId>sharding-jdbc-spring-boot-starter</artifactId>
      <version>${shardingsphere}</version>
    </dependency>
  </dependencies>

  <build>
    <pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
      <plugins>
        <!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
        <plugin>
          <artifactId>maven-clean-plugin</artifactId>
          <version>3.1.0</version>
        </plugin>
        <!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
        <plugin>
          <artifactId>maven-resources-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>3.8.0</version>
        </plugin>
        <plugin>
          <artifactId>maven-surefire-plugin</artifactId>
          <version>2.22.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-jar-plugin</artifactId>
          <version>3.0.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-install-plugin</artifactId>
          <version>2.5.2</version>
        </plugin>
        <plugin>
          <artifactId>maven-deploy-plugin</artifactId>
          <version>2.8.2</version>
        </plugin>
        <!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
        <plugin>
          <artifactId>maven-site-plugin</artifactId>
          <version>3.7.1</version>
        </plugin>
        <plugin>
          <artifactId>maven-project-info-reports-plugin</artifactId>
          <version>3.0.0</version>
        </plugin>
        <plugin>
          <groupId>org.springframework.boot</groupId>
          <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>
</project>

##yml配置

server:
  port: 8866
  servlet:
    context-path: /yym
  tomcat:
    max-threads: 300
    connection-timeout: 57000
    max-connections: 500
  connection-timeout: 57000
spring:
  datasource:
    dynamic:
      primary: master
      strict: false # 嚴(yán)格模式
      datasource:
        master:
          type: com.alibaba.druid.pool.DruidDataSource
          driver-class-name: com.mysql.cj.jdbc.Driver
          url: jdbc:mysql://192.168.3.156:3306/yymdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
          username: yym
          password: 123456
          druid:
            initialSize: 5
            minIdle: 5
            maxActive: 20
            maxWait: 60000
            timeBetweenEvictionRunsMillis: 60000
            minEvictableIdleTimeMillis: 300000
            validationQuery: SELECT 1 FROM DUAL
            testWhileIdle: true
            testOnBorrow: false
            testOnReturn: false
            webStatFilter:
              enabled: true
            statViewServlet:
              enabled: true
              url-pattern: /druid/*
              # 控制臺(tái)管理用戶名和密碼
              login-username: admin
              login-password: admin
            filter:
              stat:
                enabled: true
                # 慢SQL記錄
                log-slow-sql: true
                slow-sql-millis: 1000
                merge-sql: true
              wall:
                config:
                  multi-statement-allow: true
  shardingsphere:
    datasource:
      names: master,slave0
      master:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://192.168.3.188:3308/yymdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
        username: yym
        password: 123456
        druid:
          initialSize: 5
          minIdle: 5
          maxActive: 20
          maxWait: 60000
          timeBetweenEvictionRunsMillis: 60000
          minEvictableIdleTimeMillis: 300000
          validationQuery: SELECT 1 FROM DUAL
          testWhileIdle: true
          testOnBorrow: false
          testOnReturn: false
          webStatFilter:
            enabled: true
          statViewServlet:
            enabled: true
            url-pattern: /druid/*
            # 控制臺(tái)管理用戶名和密碼
            login-username: admin
            login-password: admin
          filter:
            stat:
              enabled: true
              # 慢SQL記錄
              log-slow-sql: true
              slow-sql-millis: 1000
              merge-sql: true
            wall:
              config:
                multi-statement-allow: true
      slave0:
        type: com.alibaba.druid.pool.DruidDataSource
        driver-class-name: com.mysql.cj.jdbc.Driver
        url: jdbc:mysql://192.168.3.188:3309/yymdb?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
        username: yym
        password: 123456
        druid:
          initialSize: 5
          minIdle: 5
          maxActive: 20
          maxWait: 60000
          timeBetweenEvictionRunsMillis: 60000
          minEvictableIdleTimeMillis: 300000
          validationQuery: SELECT 1 FROM DUAL
          testWhileIdle: true
          testOnBorrow: false
          testOnReturn: false
          webStatFilter:
            enabled: true
          statViewServlet:
            enabled: true
            url-pattern: /druid/*
            # 控制臺(tái)管理用戶名和密碼
            login-username: admin
            login-password: admin
          filter:
            stat:
              enabled: true
              # 慢SQL記錄
              log-slow-sql: true
              slow-sql-millis: 1000
              merge-sql: true
            wall:
              config:
                multi-statement-allow: true
    masterslave:
      load-balance-algorithm-type: ROUND_ROBIN
      name: ms
      master-data-source-name: master
      slave-data-source-names: slave0
mybatis-plus:
  mapper-locations: classpath*:mapper/**/*Mapper.xml
  global-config:
    db-config:
      id-type: auto
      table-underline: true
logging:
  config: classpath:config/logback-spring.xml

##mapper.xml

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.newland.mbop.mapper.PortalInfoDefMapper">

</mapper>

##TestMapper

package com.yym.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yym.entity.Test;
import org.apache.ibatis.annotations.Mapper;

@Mapper
public interface TestMapper extends BaseMapper<Test> {
}

##TestService

package com.yym.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.yym.entity.Test;
import com.yym.mapper.TestMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class TestService {

    @Autowired
    private TestMapper testMapper;

    public Test query(Test test) {
        return testMapper.selectOne(new QueryWrapper<Test>().eq("name", test.getName()));
    }

    public int add(Test test) {
        return testMapper.insert(test);
    }

}

##TestController

package com.yym.controller;

import com.yym.entity.Test;
import com.yym.service.TestService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.TimeUnit;

@RestController
@RequestMapping("/test/v1/")
public class TestController {

    @Autowired
    private TestService testService;

    Logger logger = LoggerFactory.getLogger(TestController.class);

    public TestController() {
        logger.info("TestController");
    }

    @PostMapping("tomcatTimeOut")
    public String tomcatTimeOut() {
        try {
            TimeUnit.SECONDS.sleep(120);
        }catch (Exception e) {
            e.printStackTrace();
        }
        return "sc";
    }

    @GetMapping("query")
    public String query() {
        Test test = new Test();
        test.setName("yym");
        Test testDB = testService.query(test);
        return testDB.getAddress();
    }

    @GetMapping("add")
    public String add() {
        Test test = new Test();
        test.setName("斑鳩");
        test.setAddress("枯藤老樹(shù)昏鳩");
        int count = testService.add(test);
        return count>0?"success":"fail";
    }

}

##瀏覽器訪問(wèn)

spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu),數(shù)據(jù)庫(kù),spring boot,mybatis

##數(shù)據(jù)庫(kù)

spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu),數(shù)據(jù)庫(kù),spring boot,mybatis

spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu),數(shù)據(jù)庫(kù),spring boot,mybatis文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-809815.html

到了這里,關(guān)于spring boot shardingsphere mybatis-plus druid mysql 搭建mysql數(shù)據(jù)庫(kù)讀寫分離架構(gòu)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來(lái)自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場(chǎng)。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請(qǐng)注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請(qǐng)點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • spring boot集成mybatis-plus——Mybatis Plus 查詢數(shù)據(jù)(圖文講解)

    spring boot集成mybatis-plus——Mybatis Plus 查詢數(shù)據(jù)(圖文講解)

    ?更新時(shí)間 2023-01-03 16:07:12 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過(guò) Mybatis Plus 查詢數(shù)據(jù)庫(kù)表中的數(shù)據(jù)。 在前面小節(jié)中,我們已經(jīng)定義好了一個(gè)用于測(cè)試的用戶表, 執(zhí)行腳本如下: 定義一個(gè)名為? User ?實(shí)體類: 不明白 Mybatis Plus 實(shí)體類注解的小伙伴,可參考前面

    2024年02月02日
    瀏覽(23)
  • spring boot3整合mybatis-plus

    spring boot3整合mybatis-plus

    添加依賴 配置屬性信息 編寫業(yè)務(wù)邏輯測(cè)試代碼 配置mybatis-plus分頁(yè)插件 配置mybatis-plus之屬性自動(dòng)填充 如圖所示 1、添加依賴 2、配置屬性 3、編寫測(cè)試代碼 4、XML文件 5、測(cè)試數(shù)據(jù)是否能走通

    2024年03月12日
    瀏覽(24)
  • spring boot+mybatis-plus配置讀寫分離

    對(duì)于mysql主從機(jī)制的讀寫分離,對(duì)于寫操作寫入主庫(kù),讀取操作讀取從庫(kù) 一、安裝依賴 二、配置文件配置數(shù)據(jù)源 三、在service,如果是讀取操作的話,則需要加上注解@DS(“slave”)即可,可看如下示例

    2024年01月25日
    瀏覽(21)
  • spring boot集成mybatis-plus——Mybatis Plus 批量 Insert_新增數(shù)據(jù)(圖文講解)

    spring boot集成mybatis-plus——Mybatis Plus 批量 Insert_新增數(shù)據(jù)(圖文講解)

    ?更新時(shí)間 2023-01-10 16:02:58 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過(guò) Mybatis Plus 實(shí)現(xiàn) MySQL 批量插入數(shù)據(jù)。 先拋出一個(gè)問(wèn)題:假設(shè)老板給你下了個(gè)任務(wù),向數(shù)據(jù)庫(kù)中添加 100 萬(wàn)條數(shù)據(jù),并且不能耗時(shí)太久! 通常來(lái)說(shuō),我們向 MySQL 中新增一條記錄,SQL 語(yǔ)句類似如下:

    2024年02月04日
    瀏覽(27)
  • Spring Boot + MyBatis-Plus實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀寫分離

    Spring Boot + MyBatis-Plus實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀寫分離

    ??Spring Boot + MyBatis-Plus實(shí)現(xiàn)數(shù)據(jù)庫(kù)讀寫分離 ☆* o(≧▽≦)o *☆嗨~我是IT·陳寒?? ?博客主頁(yè):IT·陳寒的博客 ??該系列文章專欄:架構(gòu)設(shè)計(jì) ??其他專欄:Java學(xué)習(xí)路線 Java面試技巧 Java實(shí)戰(zhàn)項(xiàng)目 AIGC人工智能 數(shù)據(jù)結(jié)構(gòu)學(xué)習(xí) ??文章作者技術(shù)和水平有限,如果文中出現(xiàn)錯(cuò)誤,希望

    2024年02月05日
    瀏覽(43)
  • 從零開(kāi)始學(xué)Spring Boot系列-集成MyBatis-Plus

    從零開(kāi)始學(xué)Spring Boot系列-集成MyBatis-Plus

    在Spring Boot應(yīng)用開(kāi)發(fā)中,MyBatis-Plus是一個(gè)強(qiáng)大且易于使用的MyBatis增強(qiáng)工具,它提供了很多實(shí)用的功能,如代碼生成器、條件構(gòu)造器、分頁(yè)插件等,極大地簡(jiǎn)化了MyBatis的使用和配置。本篇文章將指導(dǎo)大家如何在Spring Boot項(xiàng)目中集成MyBatis-Plus。 首先,確保你已經(jīng)安裝了Java開(kāi)發(fā)環(huán)

    2024年04月08日
    瀏覽(74)
  • spring boot集成mybatis-plus——Mybatis Plus 新增數(shù)據(jù)并返回主鍵 ID(圖文講解)

    spring boot集成mybatis-plus——Mybatis Plus 新增數(shù)據(jù)并返回主鍵 ID(圖文講解)

    ?更新時(shí)間 2023-01-10 15:37:37 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過(guò) Mybatis Plus 框架給數(shù)據(jù)庫(kù)表新增數(shù)據(jù),主要內(nèi)容思維導(dǎo)圖如下: Mybatis Plus 新增數(shù)據(jù)思維導(dǎo)圖 為了演示新增數(shù)據(jù),在前面小節(jié)中,我們已經(jīng)定義好了一個(gè)用于測(cè)試的用戶表, 執(zhí)行腳本如下: 定義一

    2024年02月02日
    瀏覽(40)
  • spring boot集成mybatis-plus——Mybatis Plus 多表聯(lián)查(包含分頁(yè)關(guān)聯(lián)查詢,圖文講解)...

    spring boot集成mybatis-plus——Mybatis Plus 多表聯(lián)查(包含分頁(yè)關(guān)聯(lián)查詢,圖文講解)...

    ?更新時(shí)間 2023-01-03 21:41:38 大家好,我是小哈。 本小節(jié)中,我們將學(xué)習(xí)如何通過(guò) Mybatis Plus 實(shí)現(xiàn) 多表關(guān)聯(lián)查詢 ,以及 分頁(yè)關(guān)聯(lián)查詢 。 本文以 查詢用戶所下訂單 ,來(lái)演示 Mybatis Plus 的關(guān)聯(lián)查詢,數(shù)據(jù)庫(kù)表除了前面小節(jié)中已經(jīng)定義好的用戶表外,再額外創(chuàng)建一張訂單表,然后

    2024年02月01日
    瀏覽(25)
  • SpringBoot整合JUnit--MyBatis--MyBatis-Plus--Druid

    SpringBoot整合JUnit--MyBatis--MyBatis-Plus--Druid

    文章轉(zhuǎn)自黑馬程序員SpringBoot學(xué)習(xí)筆記,學(xué)習(xí)網(wǎng)址:黑馬程序員SpringBoot2教程 1.整合JUnit ? SpringBoot技術(shù)的定位用于簡(jiǎn)化開(kāi)發(fā),再具體點(diǎn)是簡(jiǎn)化Spring程序的開(kāi)發(fā)。所以在整合任意技術(shù)的時(shí)候,如果你想直觀感觸到簡(jiǎn)化的效果,你必須先知道使用非SpringBoot技術(shù)時(shí)對(duì)應(yīng)的整合是如何做

    2023年04月23日
    瀏覽(23)
  • Spring Boot入門(14):使用Mybatis-Plus輕松實(shí)現(xiàn)高效自定義SQL操作!

    ? ? ? ? 在上幾期,我們既講了如何整合Mybatis-Plus進(jìn)行數(shù)據(jù)庫(kù)的增刪改查,也講解了如何使用MP的 Wrapper 構(gòu)造器,但若是遇到復(fù)雜業(yè)務(wù)邏輯,如多表聯(lián)查、動(dòng)態(tài)拼接條件等,這些操作往往會(huì)讓代碼變得冗長(zhǎng)且難以維護(hù)。但是,有了Mybatis-Plus這個(gè)優(yōu)秀的框架,我們可以輕松實(shí)現(xiàn)

    2024年02月10日
    瀏覽(24)

覺(jué)得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請(qǐng)作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包