创建springboot+mybatis项目流程
-
spring initializr创建项目
-
pom文件中导入druid-spring-boot-starter
-
配置application.yml 连接数据库
spring: datasource: url: jdbc:mysql://localhost:3306/db_account username: root password: 123456 driver-class-name: com.mysql.jdbc.Driver
-
整合mybatis,导入官方stater
<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>2.1.4</version> </dependency>
-
配置mybatis和mapper
在全局文件里配置mybatis: location
mybatis:
# config-location: classpath:mybatis/mybatis-config.xml #可以不写全局配置文件位置
mapper-locations: classpath:mybatis/mapper/*.xml #sql映射文件位置
configuration:
map-underscore-to-camel-case: true #开启驼峰命名规则
- 接口上标注mapper注解