spring boot集成mybatis框架

概述

  • 中文官网:http://www.mybatis.cn
  • 参考教程:https://www.w3cschool.cn/mybatis
  • MyBatis Plus:http://mp.baomidou.com/#/quick-start
  • 主要步骤:添加配置、生成MyBatis模板、编写服务接口、配置打包资源、编译运行测试
原理概述
程序连接数据库,反向生成程序模板。所以,要提前准备好数据库以及连接数据库的代码。
 
 
添加依赖
mybatis-spring-boot-starter,最新的版本到几就填写几,2020-05-02的版本如下:
 
<!-- mybatis -->
        <dependency>
            <groupId>org.mybatis.spring.boot</groupId>
            <artifactId>mybatis-spring-boot-starter</artifactId>
            <version>2.1.2</version>
        </dependency>
        <!-- mysql -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
        </dependency>

数据源配置

适用于Mysql5.7及以下版本,mysql8.0要使用另外的配置
spring:
  datasource:
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://192.168.177.67:3316/dbmng?useUnicode=true&zeroDateTimeBehavior=convertToNull&autoReconnect=true&characterEncoding=utf-8
    username: automng
    password: Automng_123
 添加配置类
添加MyBatis配置类,dao/model/xml等扫描
 
 
 
 
 

猜你喜欢

转载自www.cnblogs.com/perfei/p/12818889.html