springboot默认使用HikariCP连接池
引入依赖
1 2 3 4 5 6 7 8 9 10 11
| <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency>
<dependency> <groupId>com.mysql</groupId> <artifactId>mysql-connector-j</artifactId> </dependency>
|
配置
1 2 3 4 5 6 7
| spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=UTF-8&useSSL=false username: root password: root
|
测试
1 2 3 4 5 6 7 8 9 10 11 12
| @SpringBootTest public class MyTests {
@Autowired JdbcTemplate jdbcTemplate;
@Test public void test(){ List<Map<String, Object>> maps = jdbcTemplate.queryForList("select * from user"); maps.forEach(System.out::println); } }
|