SpringBoot整合JDBC
创建一个新项目。需要导入的依赖
IDEA连接数据库
在SpringBoot配置文件中连接数据池
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
url: jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=utf-8
新建一个controller文件夹创建一个类(JDBCController)用来测试
package com.Google.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
public class JDBCController {
@Autowired
JdbcTemplate jdbcTemplate;
/*直接使用jdbcTemplate类中的方法可以完美的实现增删改查
* 1.编写sql语句
* 2.使用jdbcTemplate的方法实现CURD
*
*
* */
//查询所有用户
@RequestMapping("/user")
public List
这个整合并不难,多加练习就可以掌握