JDBC
springboot: 2.3
maven: 3.3.9
spring:
datasource:
username: root
password: 123456
url: jdbc:mysql://172.20.201.255:3307/jdbc
driver-class-name: com.mysql.cj.jdbc.Driver
initialization-mode: always
hikari:
schema:
- classpath:schema-all.sql
package com.example.demo.controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import java.util.List;
import java.util.Map;
@Controller
public class HelloController {
@Autowired
JdbcTemplate jdbcTemplate;
@GetMapping("/query")
@ResponseBody
public Map<String, java.lang.Object> map(){
List<Map<String, java.lang.Object>> list = jdbcTemplate.queryForList("SELECT * from department");
return list.get(0);
}
}
逆天改命!我命由我不由天!