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

spring boot mybatis-plus dynamic-datasource 配置文件 相關依賴環(huán)境配置

這篇具有很好參考價值的文章主要介紹了spring boot mybatis-plus dynamic-datasource 配置文件 相關依賴環(huán)境配置。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

spring boot mybatis-plus dynamic-datasource 配置文件 相關依賴環(huán)境配置

##yaml配置

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 # 嚴格模式
      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/*
              # 控制臺管理用戶名和密碼
              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
mybatis-plus:
  mapper-locations: classpath*:mapper/**/*Mapper.xml
  global-config:
    db-config:
      id-type: auto
      table-underline: true

##父級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>
  </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>
  </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>

##表結(jié)構(gòu)

CREATE TABLE `t_test` (
  `id` INT NOT NULL AUTO_INCREMENT,
  `name` VARCHAR(48) COLLATE utf8mb4_general_ci DEFAULT NULL,
  `address` VARCHAR(256) COLLATE utf8mb4_general_ci DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=INNODB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci

##Test.java

package com.yym.entity;

import com.baomidou.mybatisplus.annotation.TableName;

@TableName("t_test")
public class Test {

    private int id;
    private String name;
    private String address;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

}

##TestMapper.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.java

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.java

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 test(Test test) {
        return testMapper.selectOne(new QueryWrapper<Test>().eq("name", test.getName()));
    }

}

##TestController

sudo cmake . -DCMAKE_INSTALL_PREFIX=/home/yym/mysql8-install/mysql -DMYSQL_DATADIR=/home/yym/mysql8-install/data -DSYSCONFDIR=/home/yym/mysql8-install/etc -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DWITH_PARTITION_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/home/yym/mysql8/mysql-8.1.0/boost -DWITH_DEBUG=1 -DFORCE_INSOURCE_BUILD=1

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);

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

}

##項目啟動類BootStrap.java

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BootStrap {
    public static void main(String[] args) {
        SpringApplication.run(BootStrap.class, args);
    }
}

##瀏覽器訪問

192.168.3.188:8866/yym/test/v1/test

spring boot mybatis-plus dynamic-datasource 配置文件 相關依賴環(huán)境配置,spring boot,mybatis,tomcat文章來源地址http://www.zghlxwxcb.cn/news/detail-785425.html

到了這里,關于spring boot mybatis-plus dynamic-datasource 配置文件 相關依賴環(huán)境配置的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!

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

領支付寶紅包贊助服務器費用

相關文章

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

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

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

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

    spring boot3整合mybatis-plus

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

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

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

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

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

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

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

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

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

    2024年02月05日
    瀏覽(44)
  • 從零開始學Spring Boot系列-集成MyBatis-Plus

    從零開始學Spring Boot系列-集成MyBatis-Plus

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

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

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

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

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

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

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

    2024年02月01日
    瀏覽(25)
  • Spring Boot + MyBatis-Plus 實現(xiàn) MySQL 主從復制動態(tài)數(shù)據(jù)源切換

    Spring Boot + MyBatis-Plus 實現(xiàn) MySQL 主從復制動態(tài)數(shù)據(jù)源切換

    MySQL 主從復制是一種常見的數(shù)據(jù)庫架構(gòu),它可以提高數(shù)據(jù)庫的性能和可用性。 動態(tài)數(shù)據(jù)源切換則可以根據(jù)業(yè)務需求,在不同場景下使用不同的數(shù)據(jù)源,比如在讀多寫少的場景下,可以通過切換到從庫來分擔主庫的壓力 。 在本文中,我們將介紹如何在 Spring Boot 中實現(xiàn) MySQL 動

    2024年02月19日
    瀏覽(27)
  • Spring Boot入門(14):使用Mybatis-Plus輕松實現(xiàn)高效自定義SQL操作!

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

    2024年02月10日
    瀏覽(25)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

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

二維碼1

領取紅包

二維碼2

領紅包