SpringBoot 快速整合MyBatis

来源:互联网 发布:数控车床车圆弧编程 编辑:程序博客网 时间:2024/06/08 00:59

1、添加maven依赖注解

         <!--MySQL 相关Jar包-->        <dependency>            <groupId>mysql</groupId>            <artifactId>mysql-connector-java</artifactId>            <scope>runtime</scope>        </dependency>        <!--mybatis-->        <dependency>            <groupId>org.mybatis.spring.boot</groupId>            <artifactId>mybatis-spring-boot-starter</artifactId>            <version>1.1.1</version>        </dependency>

2、配置application.yml

spring:  profiles:    active: pro# 数据库链接  datasource:    driver-class-name: com.mysql.jdbc.Driver    url: jdbc:mysql://localhost:3306/test?useUnicode=true&characterEncoding=utf-8    username: root    password:     dbcp:      max-idle: 8      min-idle: 8      initial-size: 10      max-active: 20#mybatis 配置mybatis:  type-aliases-package: com.xx.model  mapper-locations: classpath:mybatis/mapper/*.xml  configLocation: classpath:mybatis/mybatis-config.xml

3、配置mybatis-config.xml输出sql语句于控制台

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE configuration        PUBLIC "-//mybatis.org//DTD Config 3.0//EN"        "http://mybatis.org/dtd/mybatis-3-config.dtd"><configuration>    <settings>        <!-- 打印语句 -->        <setting name="logImpl" value="STDOUT_LOGGING"/>    </settings></configuration>