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
相关推荐
张涛酱1074561 天前
Subagent Orchestration 深入解析:多Agent协作的层级架构
spring·设计模式·ai编程
双普拉斯1 天前
打造工业级全栈文件管理器:深度解析上传、回收站与三重下载流控技术
spring·vue·js
aq55356001 天前
C语言、C++和C#:三大编程语言核心差异详解
java·开发语言·jvm
老马95271 天前
opencode4-在已有项目中增加修改功能
java·后端·ai编程
Moe4881 天前
Spring AI:结构化输出
java·后端·面试
sthnyph1 天前
TypeScript 与后端开发Node.js
java
逻辑驱动的ken1 天前
Java高频面试考点场景题08
java·开发语言·面试·求职招聘·春招
不恋水的雨1 天前
手动调用spring的@Validated校验
java·spring
xxjj998a1 天前
【Spring】Spring MVC案例
java·spring·mvc
阿巴斯甜1 天前
Android:MagicIndicator的使用
java