Spring boot jdbcTemplate

Spring Boot2 系列教程(十九)Spring Boot 整合 JdbcTemplate 1. 基本配置JdbcTemplate 基本用法实际上很简单,开发者在创建一个 SpringBoot 项目时,除了选择基本的 Web 依赖,再记得选上 Jdbc 依赖,以及数据库驱动依赖即可,如下:项目创建成功之后,记得添加 Druid 数据库连接池依赖(注意这里可以添加专门为 Spring Boot 打造的,而不是我们一般在 SSM 中添加的 Druid),所有添加的依赖如下:1.1.10mysql5.1.27runtime。 阅读详情

Spring boot jdbcTemplate

上一节 Spring boot lombok

Spring boot lombok

源码

springboot学习指南


jdbcTemplate

简介
spring 提供了好的的template类 简化和封装了一些便利的操作,例如 jdbcTemplte, redisTemplate,kafkaTemplate, rabbitTemplate 等等;
现在使用 jdbcTemplate 进行对数据库的操作。虽然没有mybatis 和jpa,hibernate等orm框架更先进,
不过在小型项目中偶尔还是可以使用的。

1. 引入依赖

 <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-jdbc</artifactId>
        </dependency>

        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>5.1.47</version>
        </dependency>
        <!--创建web项目-->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

2. 配置文件中配置数据源信息

server:
  port: 8989
spring:
  application:
    name: test-jdbcTemplate
  datasource:
    username: root
    password: 123456
    url: jdbc:mysql://localhost:3306/mytest?useSSL=false&charsetEncoding=utf8
    driver-class-name: com.mysql.jdbc.Driver
logging:
  level:
    org.springframework.jdbc.core: debug

3. 创建数据库表结构
创建user表

drop table t_user;
commit;
create table t_user
(
    u_id        varchar(64)                         not null
        primary key,
    u_name      varchar(32)                         not null,
    password    varchar(32)                         not null,
    money       int(10)                             null,
    create_time timestamp default CURRENT_TIMESTAMP not null
);
commit ;

创建表实体类

@ToString
public class UserEntity {

    private String uId;

    private String uName;

    private String password;

    private Long money;

    private Date createTime;

    public String getuId() {
        return uId;
    }

    public void setuId(String uId) {
        this.uId = uId;
    }

    public String getuName() {
        return uName;
    }

    public void setuName(String uName) {
        this.uName = uName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Long getMoney() {
        return money;
    }

    public void setMoney(Long money) {
        this.money = money;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }
}

使用 jdbcTemplate 进行crud 操作
jdbcTemplate 在springboot项目中已经被自动装配,在 类 JdbcTemplateConfiguration或者自动装配类JdbcTemplateAutoConfiguration 中jdbcTemplate 被创建,所以可以直接引入使用:

    @Autowired
    private JdbcTemplate jdbcTemplate;

jdbcTemplate crud 使用

jdbcTemplate.update()

insert

  @PostMapping({"", "add"})
    public String addUser(UserEntity userEntity) throws Exception {
        String id = UUID.randomUUID().toString().replaceAll("-", "");
        Object[] params = new Object[]{id,
                userEntity.getuName(),
                userEntity.getPassword(),
                userEntity.getMoney(),
                new Date()};
        jdbcTemplate.update("insert into t_user(u_id,u_name,password,money,create_time) values(?,?,?,?,?)", params);
        return id;
    }

jdbcTemplate.update 可以执行 update ,insert,和delete语句;
在这里插入图片描述
update 语句提供了以上几种重载方法;

update(String sql, @Nullable Object… args) 接收一个sql语句, 和参数;sql语句中的占位符 ? 和 参数一一对应不能有null值
update(String sql, @Nullable PreparedStatementSetter pss) 接收sql语句 和 PreparedStatementSetter;
PreparedStatementSetter 中可以使用PreparedStatement进行参数的设置
update(String sql, Object[] args, int[] argTypes) 接收一个sql语句,参数,参数类型;参数对应的数据库类型;一般情况下我们使用默认的即可,所以此方法一般不使用。
update(final String sql) 直接接收一个sql, 可以没有条件或者参数是直接拼接好了的

update

jdbcTemplate.update("update t_user set u_name = ?, password = ? where u_id = ?", new Object[]{userEntity.getuName(), userEntity.getPassword(), userEntity.getuId()})

delete

   @DeleteMapping("{id}")
    public void del(@PathVariable String id) throws Exception {
        Objects.requireNonNull(id);
        jdbcTemplate.update("delete from t_user where u_id = ?", new Object[]{id});
    }
jdbcTemplate.batchUpdate()

batch insert
批量操作 和单条操作方法基本是一致的,批量操作我们使用 BatchPreparedStatementSetter 进行参数的设置;当然不使用批量操作也可以传入参数PreparedStatementSetter

 @PostMapping({"/batch"})
    public List<String> batchAddUser(@RequestBody List<UserEntity> userEntityList) {
        List<UserEntity> collect = userEntityList.stream().map(u -> {
            u.setuId(UUID.randomUUID().toString().replaceAll("-", ""));
            u.setCreateTime(new Date());
            return u;
        }).collect(toList());

        jdbcTemplate.batchUpdate("insert into t_user(u_id,u_name,`password`,money,create_time) values(?,?,?,?,?)", new BatchPreparedStatementSetter() {
            @Override
            public void setValues(PreparedStatement ps, int i) throws SQLException {
                ps.setString(1, collect.get(i).getuId());
                ps.setString(2, collect.get(i).getuName());
                ps.setString(3, collect.get(i).getPassword());
                ps.setLong(4, collect.get(i).getMoney());
                ps.setDate(5, new java.sql.Date(collect.get(i).getCreateTime().getTime()));
            }

            @Override
            public int getBatchSize() {
                return collect.size();
            }
        });
        return collect.stream().map(UserEntity::getuId).collect(toList());
    }

collect 是我们插入的一组数据, 参数BatchPreparedStatementSetter 是我们给参数进行赋值操作,ps 这个不用说了 数据库底层的PreparedStatement , i 是 批量操作的语句的索引,也就是给索引是 i 的sql语句参数设置值;

jdbcTemplate.queryForObject()

select
使用 jdbcTemplate.queryForObject 进行查询操作

   @GetMapping({"{id}"})
    public UserEntity getUser(@PathVariable String id) throws Exception {
        return jdbcTemplate.queryForObject("select * from t_user where u_id = ?", new Object[]{id}, new BeanPropertyRowMapper<>(UserEntity.class));
    }

如果我们想要返回一个实体类,必须使用 beanPropertyRowMapper 进行映射;
queryForObject(String sql, Class requiredType) 的 requiredType 不是返回的映射实体类。
注意

	queryForObject如果没有查询出来数据会报错
	org.springframework.dao.EmptyResultDataAccessException: Incorrect result size: expected 1, actual 0
	如果使用的是queryForObject(String sql, Class<T> requiredType) 方法或其他带requiredType参数的方法;
	 这里的requiredType 是数据库的单个字段表,并不是实体类映射
	所以如果 映射为 UserEntity.class 就会报错如下:
	org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 5
    正常使用应该为  jdbcTemplate.queryForObject("select u_id from t_user where u_id = ?", new Object[]{id}, String.class);  查询数据单字段信息

例如查询用户名称

// 获取用户名
jdbcTemplate.queryForObject("select u_name from t_user where u_id = ?", new Object[]{id}, String.class);
// count
jdbcTemplate.queryForObject("select count(u_id) from t_user", Long.class);
jdbcTemplate.query()

batch select

  @GetMapping("batch")
    public List<UserEntity> getBatchUser(@RequestParam(name = "ids") String[] ids) throws Exception {
        String params = Stream.generate(() -> "?").limit(ids.length).collect(Collectors.joining(",", "", ""));
        return jdbcTemplate.query("select * from t_user where u_id in (" + params + ")", ids, new BeanPropertyRowMapper<>(UserEntity.class));
    }
jdbcTemplate.queryForList()
jdbcTemplate.queryForList("select * from t_user where u_id in (" + params + ")", ids);

queryForList 方法不能直接返回映射的实体对象;
在这里插入图片描述
参数elementType 和.queryForObject 方法的requiredType 参数一样;是单列行结果映射,就是返回只有单列数值的时候使用, 直接映射为实体bean ;则也会报错
org.springframework.jdbc.IncorrectResultSetColumnCountException: Incorrect column count: expected 1, actual 5


#### jdbcTemplate.queryForMap()

在这里插入图片描述
和queryForObject 方法基本一致;只不过返回的是个map; 不能映射为实体bean

    @GetMapping({"v2/{id}"})
    public Map<String, Object> getUser2(@PathVariable String id) throws Exception {
        return jdbcTemplate.queryForMap("select * from t_user where u_id = ?", new Object[]{id}, new BeanPropertyRowMapper<>(UserEntity.class));
    }
jdbcTemplate.execute()

batch delete

使用jdbcTemplate.execute(String sql, PreparedStatementCallback action) 方法;
execute 方法 是jdbcTemplate 的核心;所有的数据库操作方法都是调用的execute 方法;

    @DeleteMapping("batch")
    public void del(@RequestBody List<String> ids) throws Exception {
        String collect = Stream.generate(() -> "?").limit(ids.size()).collect(Collectors.joining(",", "", ""));
        jdbcTemplate.execute("delete from t_user where u_id in (" + collect + ")", new PreparedStatementCallback<Integer>() {
            @Override
            public Integer doInPreparedStatement(PreparedStatement ps) throws SQLException, DataAccessException {
                for (int i = 0; i < ids.size(); i++) {
                    ps.setString(i + 1, ids.get(i));
                }
                return ps.executeUpdate();
            }
        });
    }

NamedParameterJdbcTemplate

namedParameterJdbcTemplate 和 jdbcTemplate 都是对数据库进行操作的工具;
namedParameterJdbcTemplate 维护了一个jdbcTemplate实例; 委托给jdbcTemplate 进行操作;
使用上 是对参数 占位符 ‘?’ 进行了改变; 使用 :param 这样的形式

update 示例
    @PutMapping()
    public void update(@RequestBody UserEntity userEntity) throws Exception {
        Objects.requireNonNull(userEntity.getuId());
        namedParameterJdbcTemplate.update("update t_user set u_name = :uName, password = :password where u_id = :uId", new ObjectMapper().convertValue(userEntity, Map.class));
    }

其他操作和jdbctempalte 基本一致;

自动装配类

JdbcTemplateAutoConfiguration

@Configuration
@ConditionalOnClass({ DataSource.class, JdbcTemplate.class })
@ConditionalOnSingleCandidate(DataSource.class)
@AutoConfigureAfter(DataSourceAutoConfiguration.class)
@EnableConfigurationProperties(JdbcProperties.class)
public class JdbcTemplateAutoConfiguration {

	@Configuration
	static class JdbcTemplateConfiguration {

		private final DataSource dataSource;

		private final JdbcProperties properties;

		JdbcTemplateConfiguration(DataSource dataSource, JdbcProperties properties) {
			this.dataSource = dataSource;
			this.properties = properties;
		}

		@Bean
		@Primary
		@ConditionalOnMissingBean(JdbcOperations.class)
		public JdbcTemplate jdbcTemplate() {
			JdbcTemplate jdbcTemplate = new JdbcTemplate(this.dataSource);
			JdbcProperties.Template template = this.properties.getTemplate();
			jdbcTemplate.setFetchSize(template.getFetchSize());
			jdbcTemplate.setMaxRows(template.getMaxRows());
			if (template.getQueryTimeout() != null) {
				jdbcTemplate.setQueryTimeout((int) template.getQueryTimeout().getSeconds());
			}
			return jdbcTemplate;
		}

	}

	@Configuration
	@Import(JdbcTemplateConfiguration.class)
	static class NamedParameterJdbcTemplateConfiguration {

		@Bean
		@Primary
		@ConditionalOnSingleCandidate(JdbcTemplate.class)
		@ConditionalOnMissingBean(NamedParameterJdbcOperations.class)
		public NamedParameterJdbcTemplate namedParameterJdbcTemplate(JdbcTemplate jdbcTemplate) {
			return new NamedParameterJdbcTemplate(jdbcTemplate);
		}

	}

}

总结

jdbcTemplate 相对是封装了一下jdbcConnection原生的操作;使用上还不是很便捷,更多的我们会选择mybatis jpa 这样更抽象的


下一节 Spring boot 数据库连接池

Spring boot 数据库连接池

spring boot最新教程(三):Spring Boot整合JdbcTemplate以及事务管理 一  JdbcTemplate的使用       Spring对数据库的操作在jdbc上面做了深层次的封装,使用spring的注入功能,可以把DataSource注册到JdbcTemplate之中。 JdbcTemplate 是在JDBC API基础上提供了更抽象的封装,并提供了基于方法注解的事务管理能力。 通过使用SpringBoot自动配置功能并代替我们自动配置beans. 在maven中,我... 阅读详情

相关推荐

【Spring Boot】JdbcTemplate数据连接模板 — JdbcTemplate入门

JDBC(Java Data Base Connectivity,Java数据库连接)是Java语言中用来规范应用程序如何访问数据库的API,为多种关系数据库提供统一访问方式,诸如查询和更新数据库中数据的方法。JDBC提供了一种基准,据此可以构建更高级的工具和接口,使数据库开发人员能够编写数据库应用程序。

衍生星球的博客 1483

JdbcTemplate详解

一、JdbcTemplate(概念和准备) 1、什么是 JdbcTemplate(Template译为模板) (1)Spring 框架对 JDBC 进行封装,使用 JdbcTemplate 方便实现对数据库操作 2、准备工作 (1)引入相关 jar 包 (2)在 spring 配置文件配置数据库连接池 com.alibaba.druid.pool.DruidDataSource和com.mysql.jdbc.Driver 都是引入的jar包内的类,不需要自己创建 .

希望和大家多多交流技术! 6万+

Spring Boot:使用JdbcTemplate

JdbcTemplate相较于MyBaits,Hibernate等数据库框架更容易上手,对SQL的操作也更为直观方便,所以在项目中也是一个不错的选择。在Spring Boot开启JdbcTemplate很简单,只需要引入依赖即可。JdbcTemplate封装了许多SQL操作,具体可查阅官方文档。

新华编程特战队 1551

Spring Boot - JdbcTemplate

Spring Boot 版本:2.2.2.RELEASE 数据库:MySQL 数据表准备 MySQL 数据表定义: mysql> show create table t_user \G *************************** 1. row *************************** Table: t_user Create Table: CREATE...

qq_29761395的博客 292

jdbctemplate使用 | Spring Boot 23

一、JdbcTemplate概述 ​ JDBC已经能够满足大部分用户最基本的需求,但是在使用JDBC时,必须自己来管理数据库资源如:获取PreparedStatement,设置SQL语句参数,关闭连接等步骤。 ​ JdbcTemplate是Spring对JDBC的封装,目的是使JDBC更加易于使用。JdbcTemplate是Spring的一部分。JdbcTemplate处理了资源的建立和释放。他帮助我们避免一些常见的错误,比如忘了总要关闭连接。他运行核心的JDBC工作流,如Statement的建立和执行

学Java,找哪吒 3409

AGM Supra软件从零到一:国产CPLD工程创建全流程实战解析

本文详细解析了AGM Supra软件在国产CPLD开发中的全流程实战操作,从工程创建到代码开发、编译调试,再到高级技巧与疑难排解。特别对比了Supra与Quartus的差异,提供了工程路径管理、Quartus项目转换、HDL代码规范等实用技巧,帮助开发者高效完成CPLD项目开发。

weixin_29193259的博客 500

JdbcTemplate基本使用

JdbcTemplate基本使用 概述 开发步骤 快速入门代码实现 spring产生模板对象分析 spring产生模板对象代码实现 spring产生模板对象代码实现(抽取jdbc.properties) 常用操作-更新操作 查询操作 jdbc整合案例 实现数据添加功能:修改name和money的值

qq_52963857的博客 7312

西电计组实验二 运算器实验

算术逻辑运算实验 一.实验目的   1.了解简单运算器的数据传输通路。   2.验证运算功能发生器的组合功能。   3.掌握算术逻辑运算加、减、与的工作原理。   4.验证实验台运算的8位加、减、与、直通功能。   5.按给定数据,完成几种指定的算术和逻辑运算。 二.实验原理   算术逻辑单元ALU的数据通路如图2-1所示。其中运算器ALU181根据74LS181的功能用VHDL硬件描述语言编辑而成,构成8位字长的ALU。参加运算的两个8位数据分别为A[7…0]和B[7…0],运算模式由S[3…0]的16种

Polaris的博客 1万+

JDBCTemplate

目录 1、什么是JDBC 2、什么是JDBCTemplate 3、快速上手JDBCTemplate 4.调用JdbcTemplate的方法来完成CRUD的操作 1、什么是JDBC JDBC(Java DataBase Connectivity,java数据库连接):是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成。 2、什么是JDBCTemplate Template意思是模板,JDBCTemplate是Spring为我们

weixin_52875557的博客 6031

Java8动态生成SFunction:基于字段名的Lambda表达式实践

本文深入探讨了在Java8中如何基于字段名动态生成SFunction,以解决MyBatis Plus的LambdaQueryWrapper在动态查询场景下的局限性。通过核心原理LambdaMetafactory的解析和手把手的代码实现,展示了如何将字符串字段名转换为类型安全的Lambda表达式,从而实现真正动态、类型安全的查询条件构建与通用数据处理,显著提升代码的灵活性与安全性。

sss66的博客 952

从NASA DataPort下载到PyTorch Dataset:手把手处理USGS光谱库的AVIRIS数据

本文详细介绍了如何从NASA DataPort下载USGS光谱库的AVIRIS高光谱数据,并将其转化为PyTorch Dataset对象。内容涵盖数据获取、预处理、辐射定标及高效数据加载技巧,特别针对AVIRIS数据的水吸收波段剔除和波段分组标准化进行了重点讲解,为环境监测、地质勘探等领域的研究者提供实用指南。

weixin_30607659的博客 281

SpringBoot JdbcTemplate

文章目录JdbcTemplate基本使用一、开发工具及环境二、Spring Boot基本配置1、Spring initializr 设置2、pom.xml3、JdbcTemplateApplication类4、JdbcTemplateApplicationTests类5、MyMvcConfig类三、数据库搭建1、数据准备2、application.properties 配置数据库连接3、测试是否能连接上数据库四、整合JdbcTemplate1、创建实体类User.java2、创建UserDao.java3、

CYW2019_HUST的博客 1万+

NVIDIA驱动装好了,Gazebo为啥还是卡?手把手教你用optirun搞定GPU加速

本文详细解析了NVIDIA驱动安装后Gazebo仍卡顿的原因,并提供三步精准诊断与GPU加速实战方案。通过optirun快速启用GPU加速,解决OpenGL与显示服务器的配置问题,显著提升仿真性能。适用于ROS、PX4等开发环境,帮助用户充分利用显卡性能。

weixin_30379531的博客 464

spring boot-JdbcTemplate

​ 和mybatis相比,JdbcTemplate更加轻量级,学习成本也更加低,是直接使用sql语句的,也适合简单的CRUD(create 添加、read读取、update 修改、delete删除)操作,不过这些特点也注定了其只适合在小型项目中或者在测试中使用,只能做一些简单的CRUD操作和一些简单直接控制sql语句的场景,因此在中大型项目、需要缓存支持、需要处理动态sql等场景mybatis更胜一筹。​ 至此,我们可以快速使用JdbcTemplate。执行测试方法即可看到结果。

lxq6966892的博客 751

petalinux2022.2启动文件编译配置

petalinux2021之前的版本里,导入目录components/yocto/下的“environment-setup-aarch64-xilinx-linux” 和 “layers/core/oe-init-build-env”的环境,能使用Yocto的devtool工具。(加入下面内容,先petalinux-build下载完成后才能有源码)制作 BOOT.BIN 启动文件:petalinux-package --boot --fsbl --fpga --u-boot --force。

wangjie36的博客 1386

S7-1200PLC与昆仑通态触摸屏以太网通信的具体方法和步骤(图文)

S7-1200PLC与昆仑通态触摸屏以太网通信的具体方法和步骤(图文)

Robot_PLC_HMI_Automation 1万+

Spring Boot数据持久化之JdbcTemplate

首先我们来创建一个User Bean,如下://省略getter/setter然后来创建一个UserService类,在UserService类中注入JdbcTemplate,如下:@Service@Autowired好了,如此之后,准备工作就算完成了。

m0_74530944的博客 756

unity从3D升级到urp管线,打包ab包后,材质全部变紫色

确保材质中的被转换为 URP 兼容的着色器。在打包 AssetBundle 时,确保所需的着色器被正确打包。确保运行 AB 包的目标项目中正确配置了 URP 渲染管线。如果加载后材质丢失,检查 AB 包的加载逻辑,确保材质正确应用了着色器。通过这些步骤,你应该能够解决从标准渲染管线切换到 URP 渲染管线后,材质在 AB 包中变紫色的问题。如果问题仍然存在,请根据具体错误日志进一步排查。希望如上措施及解决方案能够帮到有需要的你。

**My Coding Family** 1962

Spring Boot中使用JdbcTemplate

个人觉得JdbcTemplate相较于MyBaits,Hibernate等数据库框架更容易上手,对SQL的操作也更为直观方便,所以在项目中也是一个不错的选择。在Spring Boot开启JdbcTemplate很简单,只需要引入spring-boot-starter-jdbc依赖即可。JdbcTemplate封装了许多SQL操作,具体可查阅官方文档https://docs.spring.io/sp...

xo_zhang的专栏 352

Statistics and Machine Learning Toolbox

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

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

Spring Boot之使用JdbcTemplate

整体步骤: (1)在pom.xml加入jdbcTemplate的依赖; (2)编写Dao类,声明为:@Repository,引入JdbcTemplate (3)编写Service类,引入Dao进行使用 (4)编写Controller进行简单测试。 具体操作流程如下: 使用JdbcTemplate类需要加入(如果在JPA已经加入的话,这个步骤就可以忽略了) &...

meng_xiaohua的博客 394

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

Spring Boot 整合持久层、 Spring Boot 整合 JdbcTemplate、Spring Boot 整合 MyBatis

Spring Boot 整合持久层 Spring Boot 整合 JdbcTemplate JdbcTemplate 是 Spring 自带的 JDBC 模版组件,底层实现了对 JDBC 的封装,用法与 MyBatis 类似,需要开发者自定义 SQL 语句,JdbcTemplate 帮助我们完成数据库的连接,SQL 执行,结果集的封装。 不足之处是灵活性不如 MyBatis,因为 MyBatis 的 SQL 语句定义在 XML 中,更有利于维护和扩展,JdbcTemplate 以硬编码的方式将 SQL 直接

weixin_44152682的博客 338

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

spring boot jdbctemplate为空_Spring Boot2 系列教程(十九)Spring Boot 整合 JdbcTemplate

在 Java 领域,数据持久化有几个常见的方案,有 Spring 自带的 JdbcTemplate 、有 MyBatis,还有 JPA,在这些方案中,最简单的就是 Spring 自带的 JdbcTemplate 了,这个东西虽然没有 MyBatis 那么方便,但是比起最开始的 Jdbc 已经强了很多了,它没有 MyBatis 功能那么强大,当然也意味着它的使用比较简单,事实上,JdbcT...

weixin_36339157的博客 727

Spring Boot 整合 JdbcTemplate,JdbcTemplate 与 MyBatis 的区别

Spring Boot 整合 JdbcTemplate,JdbcTemplate 与 MyBatis 的区别

hutao8896的博客 1180

Spring Boot JdbcTemplate 入门

1. 概述 虽然说,我们现在项目的 DAL 数据访问层,大多使用 MyBatis 或者 JPA ,但是可能极少部分情况下也会使用 JDBC 。而使用的 JDBC 一般来说,一共有 3 种方式: 原生 JDBC ,或者自己项目封装的 JDBC 工具类。 Apache Common,提供了DbUtils工具类。 Spring JDBC,提供了JdbcTemplate工具类。 因为项...

weixin_42073629的博客 205

Spring Boot 集成 JdbcTemplate(盘它!)

SpringBoot 整合 JdbcTemplate,看完还不会你别来打我。

3257

15、Spring Boot——整合jdbcTemplate

首先创建一个Spring Boot工程,添加如下依赖: 创建好之后,默认情况下数据库驱动是有一点问题的,默认情况下他的版本号定义在parent里面,但是它使用的是MySQL的最新版本,而这里我使用的MySQL是5.7的版本。所以这里很容易出现驱动版本不对的问题,这里的版本号要手动的加一下,选择适合自己MySQL的版本,我的是如下版本,大家可以结合自己的实际情况来添加: 然后再添加一个数据库驱动的...

weixin_44868863的博客 350
上一篇: Spring boot Lombok
下一篇: Spring boot 数据库连接池
xiaoduup
博客等级 码龄9年 23粉丝 83原创
评论 7
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值