1.pom 添加 Mybatis 依赖
1
2
3
4
5
6
|
<!-- Spring Boot Mybatis 依赖 -->
<dependency>
<groupId>org.mybatis.spring.boot<
/groupId
>
<artifactId>mybatis-spring-boot-starter<
/artifactId
>
<version>${mybatis-spring-boot}<
/version
>
<
/dependency
>
mybatis-spring-boot-starter 工程依赖如图:
2.在 application.properties 应用配置文件,增加 Mybatis 相关配置
mybatis.typeAliasesPackage 配置为 org.spring.springboot.domain,指向实体类包路径。mybatis.mapperLocations 配置为 classpath 路径下 mapper 包下,* 代表会扫描所有 xml 文件。
mybatis 其他配置相关详解如下:
3.在 Application 应用启动类添加注解 MapperScan
mapper 接口类扫描包配置注解 MapperScan :用这个注解可以注册 Mybatis mapper 接口类。
4.添加相应的domain类、Dao mapper接口类
|