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