本文整理了下CentOS7下mysql与Spring boot对接的基本配置,Spring boot与Mybatis结合使用。

pom.xml引入依赖

<dependency>
    <groupId>org.mybatis.spring.boot</groupId>
    <artifactId>mybatis-spring-boot-starter</artifactId>
    <version>1.1.1</version>
</dependency>
<dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.21</version>
</dependency>

搜索mapper DAO的指定 @MapperScan

@SpringBootApplication
@MapperScan("net.suninf.dao")
public class Application {

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

application.properties关于mybatis的配置

mybatis.mapper-locations=classpath:mapper/*.xml
mybatis.type-aliases-package=net.suninf.dao
mybatis.configuration.map-underscore-to-camel-case=true
mybatis.configuration.default-fetch-size=100

根据mapper配置,需要在src/main/resource/mapper目录下添加数据库操作的xml文件

如果遇到 mysql Table 'performance_schema.session_variables' doesn't exist 问题

参考:https://blog.csdn.net/whereismatrix/article/details/54018732

  1. 输入:mysql_upgrade -u root -p
  2. 重启mysql服务:service mysqld restart

mybatis配置参考