Pom导入依赖

		<dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.0.0</version>
        </dependency>

application.yml

#配置数据源,yml格式
spring:
  datasource:
     url: jdbc:mysql://127.0.0.1:3306/dianping?useUnicode=true&characterEncoding=utf8
     username: root
     password: 123
     driver-class-name: com.mysql.jdbc.Driver
#指定mybatis映射文件的地址
mybatis:
  mapper-locations: classpath:mapper/*.xml

项目结构

mybatis默认是属性名和数据库字段名一一对应的,即
数据库表列:user_name
实体类属性:user_name

但是java中一般使用驼峰命名
数据库表列:user_name
实体类属性:userName

在Springboot中,可以通过设置map-underscore-to-camel-case属性为true来开启驼峰功能。
application.properties中:

mybatis:
  configuration:
    map-underscore-to-camel-case: true

更多推荐

SpringBoot-Mybatis依赖