上一篇博文已经详细介绍了SpringBoot环境搭建过程,这一节介绍一下SpringBoot整合Mybatis。
SpringBoot整合Mybatis
方式1:mapper使用注解
项目结构
1:准备数据库数据和配置数据源
#数据源必填项 spring.datasource.driver-class-name= com.mysql.jdbc.Driver spring.datasource.url = jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8 spring.datasource.username = root spring.datasource.password = 123456
#选填 # Number of ms to wait before throwing an exception if no connection is available. spring.datasource.tomcat.max-wait=10000 # Maximum number of active connections that can be allocated from this pool at the same time. spring.datasource.tomcat.max-active=50 # Validate the connection before borrowing it from the pool. spring.datasource.tomcat.test-on-borrow=true |
2:加maven依赖
<!-- Spring-Mybatis --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.3.2</version> </dependency> <!-- MySQL驱动 --> <dependency> <groupId>mysql</groupId> <artifactId> |