Spring_Boot专栏 | ||
---|---|---|
上一篇 | 主目录 | 下一篇 |
【前言】
本文springboot整合mybatis示例使用阿里的druid
连接池(数据源),使用mysql
数据库。具体的配置druid方法见:《springboot2.X配置阿里druid数据源》
mybatis官网
注解简洁,配置版可动态sql。sql语句简单时用注解版,复杂用配置版
1 添加依赖
springboot整合mybatis需要添加mybatis的依赖,在pom.xml文件中添加mybatis的场景启动器:mybatis-spring-boot-starter
(springboot官方的场景启动器是以spring-boot-starter开头的,而mybatis的场景启动器有mybatis提供,以mybatis开头)
<!--mybatis-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
- 【注意】配置好druid连接池后,pom.xml有mysql-connector-java、spring-boot-starter-jdbc、druid的依赖。
使用lombok插件自动生成setter()\getter()\toString(),配置lombok依赖(还需要安装lombok插件):
<!--lombok-->
<dependency>
<groupId>org.projectlombok