1.添加mybatis依赖:
<dependency><groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
2.application.properties配置文件:
1.连接数据库:spring.datasource.driverClassName = com.mysql.jdbc.Driver
spring.datasource.url = jdbc:mysql://localhost:3306/数据库名
spring.datasource.username = 帐号
spring.datasource.password = 密码
2.配置mybatis:mybatis.mapper-locations=classpath:mapper/*.xml(mybatis的xml所在包)
mybatis.typeAliasesPackage=com.example.demo.dto(bean所在包)
3.启动类添加:
@MapperScan("com.example.demo.dao")(接口所在包)
或在接口上增加注解:@Mapper