springboot整合JDBC

java 复制代码
package com.qf.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
    JdbcTemplate jdbcTemplate;


    //查询数据库的所有信息
    //没有实体类,数据库的东西怎么获取?Map
    @GetMapping("/userlist")
    public List<Map<String,Object>> userList(){
            String sql="select * from test.api_time_cost";
        List<Map<String, Object>> maps = jdbcTemplate.queryForList(sql);

        return maps;



    }

}
XML 复制代码
#配置数据源
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    username: "root"
    password: "2001"
    url: jdbc:mysql://localhost:3306/test?useSSL=true&useUnicode=true&characterEncoding=utf8
相关推荐
开心香辣派小星2 小时前
23种设计模式-15解释器模式
java·设计模式·解释器模式
Halo_tjn2 小时前
虚拟机相关实验概述
java·开发语言·windows·计算机
摆烂z3 小时前
Docker与Jib(maven插件版)实战
java
RainbowSea3 小时前
从 Spring Boot 2.x 到 3.5.x + JDK21:一次完整的生产环境迁移实战
java·spring boot·后端
笨手笨脚の3 小时前
Spring Core常见错误及解决方案
java·后端·spring
奶油松果3 小时前
Springboot自动装配 - redis和redission
java·spring boot·redis
千寻技术帮3 小时前
10413_基于Springboot的智慧养老院管理系统
spring boot·mysql·源码·安装·文档·ppt·养老院
霍夫曼3 小时前
UTC时间与本地时间转换问题
java·linux·服务器·前端·javascript
VX:Fegn08953 小时前
计算机毕业设计|基于Java人力资源管理系统(源码+数据库+文档)
java·开发语言·数据库·vue.js·spring boot·后端·课程设计
荔枝hu4 小时前
springboot和shiro组合引入SseEmitter的一些坑
java·spring boot·后端·sseeitter