springboot-mybatis 配置详解

来源:互联网 发布:上海数据交易中心工资 编辑:程序博客网 时间:2024/05/17 04:59
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 相关配置
1
2
3
## Mybatis 配置
mybatis.typeAliasesPackage=org.spring.springboot.domain
mybatis.mapperLocations=classpath:mapper/*.xml
mybatis.typeAliasesPackage 配置为 org.spring.springboot.domain,指向实体类包路径。mybatis.mapperLocations 配置为 classpath 路径下 mapper 包下,* 代表会扫描所有 xml 文件。
mybatis 其他配置相关详解如下:
mybatis.config = mybatis 配置文件名称
mybatis.mapperLocations = mapper xml 文件地址
mybatis.typeAliasesPackage = 实体类包路径
mybatis.typeHandlersPackage = type handlers 处理器包路径
mybatis.check-config-location = 检查 mybatis 配置是否存在,一般命名为 mybatis-config.xml
mybatis.executorType = 执行模式。默认是 SIMPLE
3.在 Application 应用启动类添加注解 MapperScan


mapper 接口类扫描包配置注解 MapperScan :用这个注解可以注册 Mybatis mapper 接口类。
4.添加相应的domain类、Dao mapper接口类
原创粉丝点击