SpringBoot与数据访问

超详细讲解SpringBoot——数据访问 前言: 大部分系统都离不开数据访问,数据库包括SQL和NOSQL,SQL是指关系型数据库,常见的有SQL Server,Oracle,MySQL(开源),NOSQL是泛指非关系型数据库,常见的有MongoDB,Redis。 用spring开发时我们常用的ORM框架有JDBC、Mybatis,Hibernate,现在最常用的应该是Mybatis。 在Springboot中对于数据访问层,无论是SQL还是NOSQL,都默认采用整合Spring Data的方式进行统一处理,Springboot会帮我们添加大量自动 阅读详情

概述

在任何一个平台都逃离不了数据库的操作,那么在 spring boot 中怎么接入数据库呢?很简单,需要在application.properties进行配置一下,application.properties路径是 src/main/resources 下。对于 application.properties 更多的介绍请自行百度进行查找相关资料进行查看,在此不进行过多的介绍,以下只是 mysql 的配置文件。

以下将介绍JDBC、Druid数据源、MyBatis、JPA几种方式实现对MySQL的访问。

整合JDBC

引入依赖

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <scope>runtime</scope>
</dependency>

配置文件

spring:
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://192.168.15.22:3306/jdbc
    driver-class-name: com.mysql.jdbc.Driver

效果:

默认是用org.apache.tomcat.jdbc.pool.DataSource作为数据源;

数据源的相关配置都在DataSourceProperties里面;

自动配置原理:

org.springframework.boot.autoconfigure.jdbc:

1、参考DataSourceConfiguration,根据配置创建数据源,默认使用Tomcat连接池;可以使用spring.datasource.type指定自定义的数据源类型。

2、SpringBoot默认可以支持org.apache.tomcat.jdbc.pool.DataSource、HikariDataSource、BasicDataSource。

3、自定义数据源类型

/**
 * Generic DataSource configuration.
 */
@ConditionalOnMissingBean(DataSource.class)
@ConditionalOnProperty(name = "spring.datasource.type")
static class Generic {

   @Bean
   public DataSource dataSource(DataSourceProperties properties) {
       //使用DataSourceBuilder创建数据源,利用反射创建响应type的数据源,并且绑定相关属性
      return properties.initializeDataSourceBuilder().build();
   }

}

4、DataSourceInitializer:ApplicationListener;

作用:

1)、runSchemaScripts();运行建表语句;

2)、runDataScripts();运行插入数据的sql语句;

默认只需要将文件命名为:

schema-*.sql、data-*.sql
默认规则:schema.sql,schema-all.sql;
可以使用   
    schema:
      - classpath:department.sql
      指定位置

5、操作数据库:自动配置了JdbcTemplate操作数据库

整合Druid数据源

导入druid数据源
@Configuration
public class DruidConfig {

    @ConfigurationProperties(prefix = "spring.datasource")
    @Bean
    public DataSource druid(){
       return  new DruidDataSource();
    }

    //配置Druid的监控
    //1、配置一个管理后台的Servlet
    @Bean
    public ServletRegistrationBean statViewServlet(){
        ServletRegistrationBean bean = new ServletRegistrationBean(new StatViewServlet(), "/druid/*");
        Map<String,String> initParams = new HashMap<>();

        initParams.put("loginUsername","admin");
        initParams.put("loginPassword","123456");
        initParams.put("allow","");//默认就是允许所有访问
        initParams.put("deny","192.168.15.21");

        bean.setInitParameters(initParams);
        return bean;
    }

    //2、配置一个web监控的filter
    @Bean
    public FilterRegistrationBean webStatFilter(){
        FilterRegistrationBean bean = new FilterRegistrationBean();
        bean.setFilter(new WebStatFilter());

        Map<String,String> initParams = new HashMap<>();
        initParams.put("exclusions","*.js,*.css,/druid/*");

        bean.setInitParameters(initParams);

        bean.setUrlPatterns(Arrays.asList("/*"));

        return  bean;
    }
}

整合MyBatis

  • 引入依赖
<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.3.1</version>
</dependency>

步骤:

1)、配置数据源相关属性(见上一节Druid)

2)、给数据库建表

3)、创建JavaBean

  • 注解版
//指定这是一个操作数据库的mapper
@Mapper
public interface DepartmentMapper {

    @Select("select * from department where id=#{id}")
    public Department getDeptById(Integer id);

    @Delete("delete from department where id=#{id}")
    public int deleteDeptById(Integer id);

    @Options(useGeneratedKeys = true,keyProperty = "id")
    @Insert("insert into department(departmentName) values(#{departmentName})")
    public int insertDept(Department department);

    @Update("update department set departmentName=#{departmentName} where id=#{id}")
    public int updateDept(Department department);
}

问题:

自定义MyBatis的配置规则;给容器中添加一个ConfigurationCustomizer;

@org.springframework.context.annotation.Configuration
public class MyBatisConfig {

    @Bean
    public ConfigurationCustomizer configurationCustomizer(){
        return new ConfigurationCustomizer(){

            @Override
            public void customize(Configuration configuration) {
                configuration.setMapUnderscoreToCamelCase(true);
            }
        };
    }
}

使用MapperScan批量扫描所有的Mapper接口;

@MapperScan(value = "com.atguigu.springboot.mapper")
@SpringBootApplication
public class SpringBoot06DataMybatisApplication {

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

  • 配置文件版
mybatis:
  config-location: classpath:mybatis/mybatis-config.xml 指定全局配置文件的位置
  mapper-locations: classpath:mybatis/mapper/*.xml  指定sql映射文件的位置

更多使用参照 click me!

整合SpringData JPA

JPA:ORM(Object Relational Mapping)。

SpringData简介

1)、编写一个实体类(bean)和数据表进行映射,并且配置好映射关系

//使用JPA注解配置映射关系
@Entity //告诉JPA这是一个实体类(和数据表映射的类)
@Table(name = "tbl_user") //@Table来指定和哪个数据表对应;如果省略默认表名就是user;
public class User {

    @Id //这是一个主键
    @GeneratedValue(strategy = GenerationType.IDENTITY)//自增主键
    private Integer id;

    @Column(name = "last_name",length = 50) //这是和数据表对应的一个列
    private String lastName;
    @Column //省略默认列名就是属性名
    private String email;

2)、编写一个Dao接口来操作实体类对应的数据表(Repository)

//继承JpaRepository来完成对数据库的操作
public interface UserRepository extends JpaRepository<User,Integer> {
}

3)、基本的配置JpaProperties

spring:  
 jpa:
    hibernate:
#     更新或者创建数据表结构
      ddl-auto: update
#    控制台显示SQL
    show-sql: true
第三章 SpringBoot数据访问 Spring Data是Spring提供的一个用于简化数据库访问、支持云服务的开源框架。它是一个伞形项目,包含了大量关系型数据库及非关系型数据库的数据访问解决方案,其设计目的是使我们可以快速且简单的使用各种数据访问技术。SpringBoot默认采用整合Spring Data的方式统一处理数据访问层,通过添加大量自动配置,引入各种数据访问模板xxxTemplate以及统一的Repository接口,从而达到简化数据访问层的操作。 阅读详情

相关推荐

LVGL 离线字体转换lv_font_conv本地安装

LVGL FONT CONV 离线版本

liu132641的专栏 3402

springboot-Quartz定时任务并持久化

新建项目,添加依赖 新建一个springboot项目,勾选下springboot,以及quartz依赖 或者我们可以直接在pom.xml文件中直接添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-quartz</artifactId>

7348

基于STM32避障/循迹/蓝牙遥控小车的硬件与软件底层设计

1、实现2m的自动直线行驶,要求左右偏移不大于10cm。2、车载显示屏显示车辆当前行驶速度或车辆运行时间,当前方20cm内出现障碍物时显示与前方障碍物的距离,车每次转弯蜂鸣器报警,同时通过左右指示灯指示转弯方向。3、依次驶过障碍物①②③④,且不触碰障碍物。4、成功进行调头转弯,行驶过程中车轮不碾压黑实线。5、在车道指定位置停车且不越界。6、通过红外、蓝牙、WiFi等任意一种方式实现对小车的控制,使其前进、后退、左转、右转。

2301_78758161的博客 1万+

spring boot 整合 quartz 实现 动态定时任务

目标 spring boot 整合 quartz 使用自定义线程池 使用自定义数据源 动态添加 删除 暂停 恢复 定时任务的执行 项目重启后历史任务自动执行 上代码 version spring boot 2.5.6 quartz pom 依赖(spring boot 相关依赖就不放了) <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring

菜鸟阿达 1092

UE4_SpeedTree Shader源码分析

目录 1.UMaterialExpressionSpeedTree::Compile 2.Compiler->SpeedTree 3.GetSpeedTreeVertexOffset 4.Scene中的SpeedTree应用 (Scene->UpdateSpeedTreeWind) 5.GetSpeedTreeVertexOffsetInner 由于之后做风场,也需要在S...

zzgyy123的专栏 2637

手把手教你设计T型和Π型衰减器:从分贝计算到电阻选型全攻略

本文提供了一份T型和Π型衰减器的详细设计指南,涵盖从分贝计算到电阻选型的全过程。文章以50欧姆系统为例,通过公式推导和实例演示,手把手教你计算两种经典拓扑的电阻值,并深入探讨了电阻选型、误差控制及高频应用等关键实践技巧,帮助工程师和爱好者精准实现信号衰减与阻抗匹配。

blue42的博客 1350

Quartz定时任务配置参数的含义

例如,在一个分布式系统中,可以为每个节点的Quartz调度器设置不同的instanceName,以避免节点之间的任务冲突和重复执行。该属性可以设置为整数类型的值,用于指定Quartz调度器的任务触发器在misfire时的处理方式。例如,在一个分布式系统中,可以为每个节点的Quartz调度器设置不同的instanceId,以避免节点之间的任务冲突和重复执行。需要注意的是,auto-startup属性只控制Quartz调度器在启动时是否自动启动定时任务,不影响已经添加到调度器中的任务。

m0_37742400的博客 5409

用Multisim和AD2复刻经典:手把手教你搭建μA741三角波-方波发生器(附完整避坑指南)

本文详细介绍了如何使用Multisim和AD2搭建基于μA741运算放大器的三角波-方波发生器,包括电路原理、Multisim仿真流程、AD2硬件搭建及调试技巧。通过对比理论计算、仿真和实测数据,深入分析器件非理想特性的影响,并提供16个典型问题的解决方案,帮助读者掌握波形发生器的设计原理和工程调试经验。

weixin_28744423的博客 288

Spring Boot对 Quartz Scheduler的支持

Spring Boot对 Quartz Scheduler的支持

听海边涛声 776

【无人机智能避障】基于深度强化学习的城市复杂环境路径规划实战

本文探讨了基于深度强化学习的无人机在城市复杂环境中的智能避障与路径规划。针对传统算法难以应对动态与非结构化障碍的痛点,文章详细介绍了如何利用DQN算法,通过设计合理的状态空间、奖励函数,并结合经验回放、目标网络等技巧,训练无人机自主学会在楼宇间安全、高效飞行的策略。

weixin_28224217的博客 740

深入剖析 Hive 中 CASE WHEN 与 IF 函数的性能差异:解锁高效数据处理的关键

CASE WHEN 函数堪称 Hive 中条件判断的多面手,它具备两种强大的语法形式,以应对各种复杂的业务逻辑。简单 CASE 表达式这种形式适用于对某一列的值进行直接的条件匹配。其语法如下:END例如,我们有一个记录学生成绩的表CASE scoreELSE 'D'搜索 CASE 表达式当业务逻辑需要更灵活的条件判断时,搜索 CASE 表达式便派上用场。它的语法为:CASEENDCASEELSE 'D'

2401_83088008的博客 1126

SpringBoot基础-Quartz定时任务单点持久化

  io.springfox   springfox-swagger-ui   2.6.1      添加配置文

zouduchen的博客 1216

【Python】no module named distutils问题怎么解决-Numpy 启动时报错:缺少 distutils 模块的解决方法

看distutils这个名字,似乎是什么通用模块,可能不一定是numpy的问题。

每日出拳老爷子的博客 6012

Spring Boot数据访问

Spring Boot数据访问 SpringBoot数据访问概述 1.创建数据库 create database springbootdata; 2.创建表 create table `t_article`( `id` int(20) NOT NULL AUTO_INCREMENT COMMENT '文章id', `title` varchar(200) DEFAULT NULL COMMENT '文章标题', `content` longtext COMMENT '文章内容', PRIMARY K

qq_45896330的博客 9816

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

锂电池充电器电路设计 里面有电路

锂电池充电器电路设计 里面有电路 3.7V升压到5V电路设计。

Spring Boot 数据访问

通过@Query注解自定义查询语句。Query;本文从零开始介绍了 Spring Boot 数据访问的完整实现,包括如何配置数据库连接、定义实体类、实现 CRUD 操作、以及复杂查询和事务管理。通过 Spring Data JPA,数据访问变得简单而强大。Spring Boot 的数据访问能力不仅适用于小型项目,也能扩展到复杂的企业级应用。

Flying_Fish_roe的博客 1298

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

SpringBoot 数据访问

在xml中可以进行配置注入,同时也可以使用注解的方式。@Bean}}同时可以修改配置文件修改Druid的配置。但是这种方式较为麻烦,不建议使用。

JavaShark的博客 1982

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

boot spring 插入一条数据_超详细讲解SpringBoot——数据访问

一、引言大部分系统都离不开数据访问,数据库包括SQL和NOSQL,SQL是指关系型数据库,常见的有SQL Server,Oracle,MySQL(开源),NOSQL是泛指非关系型数据库,常见的有MongoDB,Redis。用spring开发时我们常用的ORM框架有JDBC、Mybatis,Hibernate,现在最常用的应该是Mybatis。在Springboot中对于数据访问层,无论是SQL还是...

weixin_33273559的博客 3280

SpringBoot——数据访问

一、SpringBoot的数据访问方式   对于数据访问层,无论是SQL还是NOSQL,SpringBoot默认采用整合SpringData的方式进行统一处理,添加大量自动配置,屏蔽了很多设置。引入各种XxxTemplate,XxxRepository来简化我们对数据访问层的操作。对我们来 说只需要进行简单的设置即可。 二、SpringBoot整合JDBC  1、创建项目,引入JDBC和Mysql...

如不來的博客 583

SpringBoot(四):Spring Boot的数据访问

1.基本概念 Spring Data 项目是Spring用来解决数据访问问题的一揽子解决方案,Spring Data是一个伞形项目,包含了大量关系型数据库和非关系型数据的数据访问解决方案。Spring Data使我们可以快速且简单的使用普通的数据访问技术及新的数据访问技术。 Spring Data包含的子项目: Spring Data JPA、Spring Data MongoDB、Spri...

鹏哥哥Aaa 438

Spring Boot 与 数据访问

JDBC 简介: 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置。引入各种xxxTemplate,xxxRepository来简化我们对数据访问层的操作。对我们来说只需要进行简单的设置即可 整合基本JDBC与数据源 引入依赖: <!--JDBC--&g...

Future_LL的博客 399

Spring Boot 与数据访问

JDBC适用于简单的数据库操作,灵活但代码冗长。JPA适合需要 ORM 支持的场景,能够自动生成 SQL,简化开发。MyBatis适合复杂查询或对 SQL 控制要求较高的场景。和适合特定类型的 NoSQL 数据库。根据你的项目需求选择合适的技术来进行数据访问。如果你使用的是 MyBatis(如你项目中提到的),那么配置和使用会基于 MyBatis 的方式。

SAFE20242034的博客 491

Spring Boot与数据访问

Spring Boot与数据访问 JBDC、MyBatis、Spring Data JPA 一、简介 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合 Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置。引入 各种xxxTemplate,xxxRepository来简化我们对数据访问层的操作。对我们来 说只需要进行简单的设置即可。我们将在...

qq_39368007的博客 223

详细SpringBoot教程之数据访问

写在前面 鉴于有人留言说想要学习SpringBoot相关的知识,我这里打算写一个SpringBoot系列的相关博文,目标呢是想让看了这一系列博文的同学呢,能够对SpringBoot略窥门径,这一系列的博文初步都定下来包括SpringBoot介绍、入门、配置、日志相关、web开发、数据访问、结合docker、缓存、消息队列、检索、任务安全、分布式等等一系列的博文,工作量很大,是个漫长的过程,每一步我...

BoCong-Deng的博客 1万+
上一篇: 云原生中间件RocketMQ基本概念&功能特性
下一篇: 太赞了!华为工程师终于总结出了Linux归纳笔记
Java技术那些事儿
博客等级 码龄5年 2306粉丝 2584原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址