本文整理了下CentOS7下mysql与Spring boot对接的基本配置,Spring boot与Mybatis结合使用。
pom.xml引入依赖
- 引入连接mysql的必要依赖
mysql-connector-java
引入整合MyBatis的核心依赖
mybatis-spring-boot-starter
<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
- 输入:
mysql_upgrade -u root -p
- 重启mysql服务:
service mysqld restart
mybatis配置参考
- https://blog.csdn.net/top_code/article/details/78569342
- https://www.cnblogs.com/liangblog/p/5228548.html
- https://blog.csdn.net/clementad/article/details/52944505
- http://blog.didispace.com/springbootmybatis/
- https://blog.csdn.net/qq_33337504/article/details/78460383
- https://www.jianshu.com/p/13616babe6ae