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
相关推荐
superlls3 分钟前
(场景题)Java 导出 Excel 的两种方式
java·开发语言·后端·excel
harmful_sheep11 分钟前
springMvc
java
一只小透明啊啊啊啊13 分钟前
Java电商项目中的概念: 高并发、分布式、高可用、微服务、海量数据处理
java·分布式·微服务
2401_841495643 小时前
【数据结构】基于Prim算法的最小生成树
java·数据结构·c++·python·算法·最小生成树·prim
木井巳4 小时前
[Java数据结构和算法] HashMap 和 HashSet
java·数据结构·1024程序员节
祈祷苍天赐我java之术5 小时前
解析常见的限流算法
java·数据结构·算法
摇滚侠5 小时前
IDEA 启动前端项目 IDEA 切换分支
java·ide·intellij-idea
元直数字电路验证5 小时前
Jakarta EE开发中,如何配置IntelliJ IDEA的远程调试?
java·eureka·intellij-idea
石头wang5 小时前
idea字体的问题(idea应用本身的字体问题)
java·ide·intellij-idea
孔明兴汉6 小时前
第一章-第三节-Java开发环境配置
java·开发语言