1、第一个包扫描nameSpace是扫描Dao层,第二个是扫描Bean层
2、Mybatis配置包扫描和映射文件路径,一定一定要写包的映射文件路径和包扫描:下面的映射文件路径,type扫描一定要写,不写接口数据导不出来
spring: datasource: driver-class-name: com.mysql.cj.jdbc.Driver url: jdbc:mysql://localhost:3306/zero?serverTimezone=UTC username: xxxx password: xxxx mybatis: mapper-locations: classpath:mappers/*.xml type-aliases-package: zero.file.videoProject.mybatis.entity
3、Mybatis的相关依赖:
<dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-jdbc</artifactId> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.2.2</version> </dependency> <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> </dependencies>
4、启动类要放对位置