SpringBoot整合MyBatis
1: 添加依赖 mybatis
<!--springBoot整合Mybatis依赖--> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version> </dependency>
2:在配置文件中配置数据源信息(这里使用的是后缀名yaml配置文件)
spring: datasource: driver-class-name: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/springboot username: root password: ROOT
3:编写pojo mapper接口 mapeer映射文件
4:手动配置mybatis的包扫描
在主启动类添加@MapperScan
5.错误:org.apache.ibatis.binding.BindingException: Invalid bound statement (not found): com.offcn.mapper.UserMapper.getUserList
<build> <!--由于java目录下的xml文件,不能够被编译,因此这里的意思就是将java目录下xml放在resources下--> <resources> <resource> <directory>src/main/java</directory> <includes> <include>**/*.properties</include> <include>**/*.xml</include> </includes> <filtering>false</filtering> </resource> <resource> <directory>src/main/resources</directory> <includes> <include>**/*.*</include> </includes> <filtering>false</filtering> </resource> </resources> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build>