一、添加pom依赖jar包:
1 23 7 8 9org.mybatis.spring.boot 4mybatis-spring-boot-starter 51.1.1 610 com.zaxxer 11HikariCP-java6 122.3.9 13compile 14
二、项目结构:
Mapper文件在resources目录下。并在SpringBoot入口类中添加 @MapperScan("cn.com.venus.oa.mapper") @ServletComponentScan 注解
在入口类上添加注解,配置Mapper接口的地址
1 @ServletComponentScan2 @MapperScan("cn.com.venus.oa.mapper")3 public class venusAppcliation {4 ... 5 }
@ServletComponentScan: 设置启动时spring能够扫描到我们自己编写的servlet和filter
@MapperScan: 用于扫描的mapper接口
在yml配置文件中:
1 spring: 2 datasource: 3 driver-class-name: com.mysql.jdbc.Driver 4 url: jdbc:mysql:///venus 5 username: root 6 password: admin 7 8 mvc: 9 view:10 prefix: /WEB-INF/pages/11 suffix: .jsp12 13 mybatis:14 type-aliases-package: cn.com.venus.oa.pojo15 config-location: classpath:/mybatis/mybatis-config.xml16 mapper-locations: classpath:/mybatis/mappers/*.xml