- SpringBoot整合JDBC练习使用
- 一、引入JDBC依赖和Mysql数据库驱动
- 二、配置数据库数据源
- 三、接口
二、配置数据库数据源org.springframework.boot spring-boot-starter-jdbc mysql mysql-connector-java runtime
创建application.yml文件,并输入以下配置
spring:
datasource:
username: root
password: mysql
#假如时区报错,就添加一个时区的配置: serverTimezone=UTC
url: jdbc:mysql://localhost:3306/test?useUnicode=true&serverTimezone=UTC&characterEncoding=utf-8
driver-class-name: com.mysql.cj.jdbc.Driver
三、接口
package com.example.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.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
import java.util.Map;
@RestController
public class JDBCController {
@Autowired
private JdbcTemplate jdbcTemplate;
//没有实体类,数据库中的数据怎么获取? 使用map
@GetMapping("/userList")
public List


