1 数据库配置
Spring Boot支持.properties格式和.yml格式配置文件,根据个人习惯可以随意选择(笔者推荐yml格式,可读性更强)。在classpath路径下创建application.properties文件或者application.yml文件。两种类型配置分别如下
.yml配置文件
spring:
datasource:
driver-class-name: com.mysql.jdbc.Driver
url: jdbc:mysql://localhost/test
username: root
password: 123456
注意: .yml类型文件,属性名后面冒号和值之间必须有一个空格,如username: root是正确格式, 但是useranme:root格式就是错误的。
.properties文件配置
spring.datasource.url=jdbc:mysql://localhost:3306/test?serverTimezone=GMT%2B8&characterEncoding=utf-8&useSSL=false spring.datasource.username=root spring.datasource.password=123456 spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver mybatis.mapper-locations=classpath:mapper/*.xml
2 在启动类上加注解 @MapperScan 指明 mapper 类的位置
@MapperScan("com.solo.coderiver.project.mapper")
public class ProjectApplication {
public static void main(String[] args) {
SpringApplication.run(ProjectApplication.class, args);
}
}



