链接数据库
在pom.xml导入数据库的依赖(springboot有数据依赖版本号,所以这里不写版本号)
mysql mysql-connector-java runtimeorg.springframework.boot spring-boot-starter-jdbc
链接数据库的配置
新建一个配置文件application.yml 也可以用application.properties配置,只是写法不同,application.properties有中文乱码问题
spring: datasource: url: jdbc:mysql://localhost:3306/springboot?serverTimezone=UTC username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver
测试一下:
@SpringBootTestclass MybatisappApplicationTests { @Autowired DataSource dataSour