- idea
- jdk 1.8
- maven 3.6.3
利用 idea 新建一个简单的 springboot 项目,名为 springboot-jdbc ,此处省略过程
2、引入依赖在 pom.xml 文件中加入依赖,这里直接给出所有依赖内容
3、更改配置4.0.0 org.springframework.boot spring-boot-starter-parent 2.7.2 com.yuhuofei springboot-jdbc 0.0.1-SNAPSHOT springboot-jdbc springboot整合jdbc 1.8 org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime org.springframework.boot spring-boot-starter-test test org.springframework.boot spring-boot-starter-web org.springframework.boot spring-boot-maven-plugin
在项目的 application.yaml 配置文件中,加入以下配置
spring:
datasource:
username: root
password: pan
url: jdbc:mysql://localhost:3306/mybatis?useSSL=true&useUnicode=true&characterEncoding=utf-8&serverTimezone=UTC
driver-class-name: com.mysql.cj.jdbc.Driver
4、测 试
新建一个 JDBCController.java 类,内容如下
package com.yuhuofei.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
public class JDBCController {
@Autowired
private JdbcTemplate jdbcTemplate;
//查询数据库的所有信息
@GetMapping("/userList")
public List
整个项目的目录结构如下
启动项目测试
1、启动项目
2、打开浏览器或者 postman 或者其它接口调试工具,然后访问 http://localhost:8080/userList
3、结果如下所示



