Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化

1. 创建项目,添加web依赖、jdbc依赖、mysql连接依赖、druid连接池依赖

Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化


 

2.  在application.rpoperies中配置数据库连接信息

Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化

type是数据库连接池的全类名,url是连接字符串,username与password分别是账号与密码


 

3.创建实体类

Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化


 

4.创建Repository层

Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化

需要注入JdbcTemplate对象。 

增删改操作主要使用update与batchUpdate函数进行操作。query与queryForObject主要用于查询。call用来执行存储过程。

查询操作需要使用rowMapper进行映射,如果列名与属性名一致,可以直接使用BeanPropertyRowMapper


 

5.创建Service层

Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化


 

6. 创建Controller调用

Spring boot+Vue全栈开发---整合JdbcTemplate进行数据持久化