0x00 配置application.properties
mysql默认SSL登录,使用useSSL=false可忽略。
直接连接到数据库member时,jdbc:mysql://127.0.0.1:3306/member?useSSL=false
spring.datasource.url=jdbc:mysql://127.0.0.1:3306?useSSL=false
spring.datasource.username=root
spring.datasource.password=pwd
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
0x01 添加依赖pom.xml
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>
0x02 数据库增删改查
@Autowired
private JdbcTemplate jdbcTemplate;
// ...
List<Map<String, Object>> list = jdbcTemplate.queryForList(sql);