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
相关推荐
m0_7482478015 分钟前
SOA(面向服务架构)全面解析
java·微服务·架构
m0_7401546719 分钟前
Tomcat
java·tomcat
m0_7482338819 分钟前
Spring Boot 集成 MyBatis 全面讲解
spring boot·后端·mybatis
爱敲代码的小冰26 分钟前
【Excel】 Power Query抓取多页数据导入到Excel
android·java·excel
心流时间40 分钟前
[Java基础] JVM常量池介绍(BeanUtils.copyProperties(source, target)中的属性值引用的是同一个对象吗)
java·开发语言·jvm
快乐非自愿1 小时前
Spring Boot集成Spring Security之HTTP请求授权
spring boot·spring·http
瑞金彭于晏1 小时前
通俗易懂版 Maven 科普,maven是什么?
java·maven
好看资源平台1 小时前
Java Web开发实战与项目——Spring Boot与Spring Cloud微服务项目实战
java
不懂901 小时前
Spring Boot集成Jetty、Tomcat或Undertow及支持HTTP/2协议
spring boot·后端·http·https
.猫的树1 小时前
Java集合List快速实现重复判断的10种方法深度解析
java·开发语言·list·集合