java

关注公众号 jb51net

关闭
首页 > 软件编程 > java > springboot数据访问和数据库集成

Spring Boot 数据访问与数据库集成的应用场景解析

作者:星辰徐哥

本文给大家介绍Spring Boot数据访问与数据库集成的应用场景解析,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

Spring Boot 数据访问与数据库集成

18.1 学习目标与重点提示

学习目标:掌握Spring Boot数据访问与数据库集成的核心概念与使用方法,包括Spring Boot数据访问的基本方法、Spring Boot与MySQL的集成、Spring Boot与H2的集成、Spring Boot与MyBatis的集成、Spring Boot与JPA的集成、Spring Boot的事务管理、Spring Boot的实际应用场景,学会在实际开发中处理数据库访问问题。
重点:Spring Boot数据访问的基本方法Spring Boot与MySQL的集成Spring Boot与H2的集成Spring Boot与MyBatis的集成Spring Boot与JPA的集成Spring Boot的事务管理Spring Boot的实际应用场景

18.2 Spring Boot数据访问概述

Spring Boot数据访问是指使用Spring Boot进行数据库操作的方法。

18.2.1 数据访问的定义

定义:数据访问是指使用Spring Boot进行数据库操作的方法。
作用

✅ 结论:数据访问是指使用Spring Boot进行数据库操作的方法,作用是实现数据库的增删改查、事务管理、数据的持久化。

18.2.2 数据访问的常用组件

定义:数据访问的常用组件是指Spring Boot提供的数据访问组件。
组件

✅ 结论:数据访问的常用组件包括JdbcTemplate、JPA、MyBatis、Hibernate。

18.3 Spring Boot与MySQL的集成

Spring Boot与MySQL的集成是最常用的数据访问方法之一。

18.3.1 集成MySQL的步骤

定义:集成MySQL的步骤是指使用Spring Boot与MySQL集成的方法。
步骤

  1. 在pom.xml文件中添加MySQL依赖。
  2. 在application.properties或application.yml文件中配置MySQL连接信息。
  3. 创建实体类。
  4. 创建Repository接口。
  5. 创建控制器类。
  6. 测试应用。

示例
pom.xml文件中的MySQL依赖:

<dependencies>
    <!-- Web依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- Data JPA依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!-- MySQL依赖 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- 测试依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

application.properties文件中的MySQL连接信息:

# 服务器端口
server.port=8080
# 数据库连接信息
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
# JPA配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

实体类:

import javax.persistence.*;
@Entity
@Table(name = "product")
public class Product {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String productId;
    private String productName;
    private double price;
    private int sales;
    public Product() {
    }
    public Product(String productId, String productName, double price, int sales) {
        this.productId = productId;
        this.productName = productName;
        this.price = price;
        this.sales = sales;
    }
    // Getter和Setter方法
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }
    public String getProductName() {
        return productName;
    }
    public void setProductName(String productName) {
        this.productName = productName;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public int getSales() {
        return sales;
    }
    public void setSales(int sales) {
        this.sales = sales;
    }
    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", productId='" + productId + '\'' +
                ", productName='" + productName + '\'' +
                ", price=" + price +
                ", sales=" + sales +
                '}';
    }
}

Repository接口:

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
    List<Product> findBySalesGreaterThan(int sales);
}

控制器类:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/products")
public class ProductController {
    @Autowired
    private ProductRepository productRepository;
    @GetMapping("/")
    public List<Product> getAllProducts() {
        return productRepository.findAll();
    }
    @PostMapping("/")
    public Product addProduct(@RequestBody Product product) {
        return productRepository.save(product);
    }
    @GetMapping("/top-selling")
    public List<Product> getTopSellingProducts(@RequestParam int topN) {
        List<Product> products = productRepository.findBySalesGreaterThan(0);
        products.sort((p1, p2) -> p2.getSales() - p1.getSales());
        if (products.size() > topN) {
            return products.subList(0, topN);
        }
        return products;
    }
}

测试类:

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
class ProductApplicationTests {
    @Autowired
    private ProductController productController;
    @Test
    void contextLoads() {
    }
    @Test
    void testGetAllProducts() {
        List<Product> products = productController.getAllProducts();
        assertEquals(5, products.size());
    }
    @Test
    void testAddProduct() {
        Product product = new Product("P006", "平板", 2000.0, 70);
        Product addedProduct = productController.addProduct(product);
        assertEquals("P006", addedProduct.getProductId());
    }
    @Test
    void testGetTopSellingProducts() {
        List<Product> topSellingProducts = productController.getTopSellingProducts(3);
        assertEquals(3, topSellingProducts.size());
        assertEquals("P004", topSellingProducts.get(0).getProductId());
        assertEquals("P005", topSellingProducts.get(1).getProductId());
        assertEquals("P001", topSellingProducts.get(2).getProductId());
    }
}

✅ 结论:集成MySQL的步骤包括添加MySQL依赖、配置MySQL连接信息、创建实体类、创建Repository接口、创建控制器类、测试应用。

18.4 Spring Boot与H2的集成

Spring Boot与H2的集成是用于开发和测试的常用方法之一。

18.4.1 集成H2的步骤

定义:集成H2的步骤是指使用Spring Boot与H2集成的方法。
步骤

  1. 在pom.xml文件中添加H2依赖。
  2. 在application.properties或application.yml文件中配置H2连接信息。
  3. 创建实体类。
  4. 创建Repository接口。
  5. 创建控制器类。
  6. 测试应用。

示例
pom.xml文件中的H2依赖:

<dependencies>
    <!-- Web依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- Data JPA依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!-- H2数据库依赖 -->
    <dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- 测试依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

application.properties文件中的H2连接信息:

# 服务器端口
server.port=8080
# 数据库连接信息
spring.datasource.url=jdbc:h2:mem:testdb
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
# JPA配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true
# H2数据库控制台
spring.h2.console.enabled=true
spring.h2.console.path=/h2-console

实体类、Repository接口、控制器类、测试类与集成MySQL的示例相同。

✅ 结论:集成H2的步骤包括添加H2依赖、配置H2连接信息、创建实体类、创建Repository接口、创建控制器类、测试应用。

18.5 Spring Boot与MyBatis的集成

Spring Boot与MyBatis的集成是常用的数据访问方法之一。

18.5.1 集成MyBatis的步骤

定义:集成MyBatis的步骤是指使用Spring Boot与MyBatis集成的方法。
步骤

  1. 在pom.xml文件中添加MyBatis依赖。
  2. 在application.properties或application.yml文件中配置MyBatis连接信息。
  3. 创建实体类。
  4. 创建Mapper接口。
  5. 创建Mapper XML文件。
  6. 创建控制器类。
  7. 测试应用。

示例
pom.xml文件中的MyBatis依赖:

<dependencies>
    <!-- Web依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- MyBatis依赖 -->
    <dependency>
        <groupId>org.mybatis.spring.boot</groupId>
        <artifactId>mybatis-spring-boot-starter</artifactId>
        <version>2.3.0</version>
    </dependency>
    <!-- MySQL依赖 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- 测试依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

application.properties文件中的MyBatis连接信息:

# 服务器端口
server.port=8080
# 数据库连接信息
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
# MyBatis配置
mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=com.example.demo.entity

实体类:

public class Product {
    private Long id;
    private String productId;
    private String productName;
    private double price;
    private int sales;
    public Product() {
    }
    public Product(String productId, String productName, double price, int sales) {
        this.productId = productId;
        this.productName = productName;
        this.price = price;
        this.sales = sales;
    }
    // Getter和Setter方法
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }
    public String getProductName() {
        return productName;
    }
    public void setProductName(String productName) {
        this.productName = productName;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public int getSales() {
        return sales;
    }
    public void setSales(int sales) {
        this.sales = sales;
    }
    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", productId='" + productId + '\'' +
                ", productName='" + productName + '\'' +
                ", price=" + price +
                ", sales=" + sales +
                '}';
    }
}

Mapper接口:

import org.apache.ibatis.annotations.Mapper;
import java.util.List;
@Mapper
public interface ProductMapper {
    List<Product> findAll();
    int insert(Product product);
    List<Product> findBySalesGreaterThan(int sales);
}

Mapper XML文件(src/main/resources/mapper/ProductMapper.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.example.demo.mapper.ProductMapper">
    <resultMap id="ProductResultMap" type="com.example.demo.entity.Product">
        <id property="id" column="id"/>
        <result property="productId" column="product_id"/>
        <result property="productName" column="product_name"/>
        <result property="price" column="price"/>
        <result property="sales" column="sales"/>
    </resultMap>
    <select id="findAll" resultMap="ProductResultMap">
        SELECT * FROM product
    </select>
    <insert id="insert" parameterType="com.example.demo.entity.Product">
        INSERT INTO product (product_id, product_name, price, sales) VALUES (#{productId}, #{productName}, #{price}, #{sales})
    </insert>
    <select id="findBySalesGreaterThan" parameterType="int" resultMap="ProductResultMap">
        SELECT * FROM product WHERE sales > #{sales}
    </select>
</mapper>

控制器类:

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
@RestController
@RequestMapping("/api/products")
public class ProductController {
    @Autowired
    private ProductMapper productMapper;
    @GetMapping("/")
    public List<Product> getAllProducts() {
        return productMapper.findAll();
    }
    @PostMapping("/")
    public int addProduct(@RequestBody Product product) {
        return productMapper.insert(product);
    }
    @GetMapping("/top-selling")
    public List<Product> getTopSellingProducts(@RequestParam int topN) {
        List<Product> products = productMapper.findBySalesGreaterThan(0);
        products.sort((p1, p2) -> p2.getSales() - p1.getSales());
        if (products.size() > topN) {
            return products.subList(0, topN);
        }
        return products;
    }
}

测试类:

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
class ProductApplicationTests {
    @Autowired
    private ProductController productController;
    @Test
    void contextLoads() {
    }
    @Test
    void testGetAllProducts() {
        List<Product> products = productController.getAllProducts();
        assertEquals(5, products.size());
    }
    @Test
    void testAddProduct() {
        Product product = new Product("P006", "平板", 2000.0, 70);
        int count = productController.addProduct(product);
        assertEquals(1, count);
    }
    @Test
    void testGetTopSellingProducts() {
        List<Product> topSellingProducts = productController.getTopSellingProducts(3);
        assertEquals(3, topSellingProducts.size());
        assertEquals("P004", topSellingProducts.get(0).getProductId());
        assertEquals("P005", topSellingProducts.get(1).getProductId());
        assertEquals("P001", topSellingProducts.get(2).getProductId());
    }
}

✅ 结论:集成MyBatis的步骤包括添加MyBatis依赖、配置MyBatis连接信息、创建实体类、创建Mapper接口、创建Mapper XML文件、创建控制器类、测试应用。

18.6 Spring Boot与JPA的集成

Spring Boot与JPA的集成是常用的数据访问方法之一。

18.6.1 集成JPA的步骤

定义:集成JPA的步骤是指使用Spring Boot与JPA集成的方法。
步骤

  1. 在pom.xml文件中添加JPA依赖。
  2. 在application.properties或application.yml文件中配置JPA连接信息。
  3. 创建实体类。
  4. 创建Repository接口。
  5. 创建控制器类。
  6. 测试应用。

示例
pom.xml文件中的JPA依赖:

<dependencies>
    <!-- Web依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-web</artifactId>
    </dependency>
    <!-- Data JPA依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-data-jpa</artifactId>
    </dependency>
    <!-- MySQL依赖 -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <scope>runtime</scope>
    </dependency>
    <!-- 测试依赖 -->
    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-test</artifactId>
        <scope>test</scope>
    </dependency>
</dependencies>

application.properties文件中的JPA连接信息:

# 服务器端口
server.port=8080
# 数据库连接信息
spring.datasource.url=jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8&useSSL=false&serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.username=root
spring.datasource.password=123456
# JPA配置
spring.jpa.hibernate.ddl-auto=update
spring.jpa.show-sql=true

实体类、Repository接口、控制器类、测试类与集成MySQL的示例相同。

✅ 结论:集成JPA的步骤包括添加JPA依赖、配置JPA连接信息、创建实体类、创建Repository接口、创建控制器类、测试应用。

18.7 Spring Boot的事务管理

Spring Boot的事务管理是数据访问的重要组件。

18.7.1 事务管理的定义

定义:事务管理是指使用Spring Boot进行事务处理的方法。
作用

常用注解

示例

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;
@Service
public class ProductService {
    @Autowired
    private ProductRepository productRepository;
    @Transactional
    public void addProduct(Product product) {
        productRepository.save(product);
    }
    @Transactional
    public void updateProduct(Product product) {
        productRepository.save(product);
    }
    @Transactional
    public void deleteProduct(Long id) {
        productRepository.deleteById(id);
    }
    @Transactional(readOnly = true)
    public List<Product> getAllProducts() {
        return productRepository.findAll();
    }
    @Transactional(readOnly = true)
    public List<Product> getTopSellingProducts(int topN) {
        List<Product> products = productRepository.findBySalesGreaterThan(0);
        products.sort((p1, p2) -> p2.getSales() - p1.getSales());
        if (products.size() > topN) {
            return products.subList(0, topN);
        }
        return products;
    }
}

✅ 结论:事务管理是指使用Spring Boot进行事务处理的方法,常用注解包括@Transactional。

18.8 Spring Boot的实际应用场景

在实际开发中,Spring Boot数据访问与数据库集成的应用场景非常广泛,如:

示例

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;
import javax.persistence.*;
import java.util.List;
// 产品类
@Entity
@Table(name = "product")
public class Product {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String productId;
    private String productName;
    private double price;
    private int sales;
    public Product() {
    }
    public Product(String productId, String productName, double price, int sales) {
        this.productId = productId;
        this.productName = productName;
        this.price = price;
        this.sales = sales;
    }
    // Getter和Setter方法
    public Long getId() {
        return id;
    }
    public void setId(Long id) {
        this.id = id;
    }
    public String getProductId() {
        return productId;
    }
    public void setProductId(String productId) {
        this.productId = productId;
    }
    public String getProductName() {
        return productName;
    }
    public void setProductName(String productName) {
        this.productName = productName;
    }
    public double getPrice() {
        return price;
    }
    public void setPrice(double price) {
        this.price = price;
    }
    public int getSales() {
        return sales;
    }
    public void setSales(int sales) {
        this.sales = sales;
    }
    @Override
    public String toString() {
        return "Product{" +
                "id=" + id +
                ", productId='" + productId + '\'' +
                ", productName='" + productName + '\'' +
                ", price=" + price +
                ", sales=" + sales +
                '}';
    }
}
// 产品Repository
@Repository
public interface ProductRepository extends JpaRepository<Product, Long> {
    List<Product> findBySalesGreaterThan(int sales);
}
// 产品Service
@Service
public class ProductService {
    @Autowired
    private ProductRepository productRepository;
    @Transactional
    public void addProduct(Product product) {
        productRepository.save(product);
    }
    @Transactional
    public void updateProduct(Product product) {
        productRepository.save(product);
    }
    @Transactional
    public void deleteProduct(Long id) {
        productRepository.deleteById(id);
    }
    @Transactional(readOnly = true)
    public List<Product> getAllProducts() {
        return productRepository.findAll();
    }
    @Transactional(readOnly = true)
    public List<Product> getTopSellingProducts(int topN) {
        List<Product> products = productRepository.findBySalesGreaterThan(0);
        products.sort((p1, p2) -> p2.getSales() - p1.getSales());
        if (products.size() > topN) {
            return products.subList(0, topN);
        }
        return products;
    }
}
// 产品控制器
@RestController
@RequestMapping("/api/products")
public class ProductController {
    @Autowired
    private ProductService productService;
    @GetMapping("/")
    public List<Product> getAllProducts() {
        return productService.getAllProducts();
    }
    @PostMapping("/")
    public void addProduct(@RequestBody Product product) {
        productService.addProduct(product);
    }
    @PutMapping("/{id}")
    public void updateProduct(@PathVariable Long id, @RequestBody Product product) {
        product.setId(id);
        productService.updateProduct(product);
    }
    @DeleteMapping("/{id}")
    public void deleteProduct(@PathVariable Long id) {
        productService.deleteProduct(id);
    }
    @GetMapping("/top-selling")
    public List<Product> getTopSellingProducts(@RequestParam int topN) {
        return productService.getTopSellingProducts(topN);
    }
}
// 应用启动类
@SpringBootApplication
public class ProductApplication {
    public static void main(String[] args) {
        SpringApplication.run(ProductApplication.class, args);
    }
    @Autowired
    private ProductService productService;
    public void run(String... args) {
        // 初始化数据
        productService.addProduct(new Product("P001", "手机", 1000.0, 100));
        productService.addProduct(new Product("P002", "电脑", 5000.0, 50));
        productService.addProduct(new Product("P003", "电视", 3000.0, 80));
        productService.addProduct(new Product("P004", "手表", 500.0, 200));
        productService.addProduct(new Product("P005", "耳机", 300.0, 150));
    }
}
// 测试类
@SpringBootTest
class ProductApplicationTests {
    @Autowired
    private ProductController productController;
    @Test
    void contextLoads() {
    }
    @Test
    void testGetAllProducts() {
        List<Product> products = productController.getAllProducts();
        assertEquals(5, products.size());
    }
    @Test
    void testAddProduct() {
        Product product = new Product("P006", "平板", 2000.0, 70);
        productController.addProduct(product);
        List<Product> products = productController.getAllProducts();
        assertEquals(6, products.size());
    }
    @Test
    void testUpdateProduct() {
        Product product = new Product("P001", "手机", 1500.0, 120);
        productController.updateProduct(1L, product);
        List<Product> products = productController.getAllProducts();
        assertEquals(1500.0, products.get(0).getPrice());
    }
    @Test
    void testDeleteProduct() {
        productController.deleteProduct(2L);
        List<Product> products = productController.getAllProducts();
        assertEquals(4, products.size());
    }
    @Test
    void testGetTopSellingProducts() {
        List<Product> topSellingProducts = productController.getTopSellingProducts(3);
        assertEquals(3, topSellingProducts.size());
        assertEquals("P004", topSellingProducts.get(0).getProductId());
        assertEquals("P005", topSellingProducts.get(1).getProductId());
        assertEquals("P001", topSellingProducts.get(2).getProductId());
    }
}

输出结果

✅ 结论:在实际开发中,Spring Boot数据访问与数据库集成的应用场景非常广泛,需要根据实际问题选择合适的数据访问方法。

总结

本章我们学习了Spring Boot数据访问与数据库集成,包括Spring Boot数据访问的基本方法、Spring Boot与MySQL的集成、Spring Boot与H2的集成、Spring Boot与MyBatis的集成、Spring Boot与JPA的集成、Spring Boot的事务管理、Spring Boot的实际应用场景,学会了在实际开发中处理数据库访问问题。其中,Spring Boot数据访问的基本方法、Spring Boot与MySQL的集成、Spring Boot与H2的集成、Spring Boot与MyBatis的集成、Spring Boot与JPA的集成、Spring Boot的事务管理、Spring Boot的实际应用场景是本章的重点内容。从下一章开始,我们将学习Spring Boot的其他组件、微服务等内容。

到此这篇关于Spring Boot 数据访问与数据库集成的文章就介绍到这了,更多相关springboot数据访问和数据库集成内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

您可能感兴趣的文章:
阅读全文