SpringBoot项目如何集成依赖Mybatis
1、先新建或者打开你的springboot项目
2、打开你的pom.xml文件,定位的依赖的洧粽袄淖配置部分,然后加入以下依赖,这是依赖mybatis框架<dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter</artifactId> <version>1.1.1</version></dependency>
3、接着再加入以下依赖,这是指定mybatis框架的实现技术为mysql数据库,这里不需要配置具体数据库的版本.<dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId></dependency>
4、在resource目录下创建一个application.yml文件,在里面配置数据库的连接信息
5、如图,根据你的实际信息按以下格式填写数倌栗受绽据库的连接信息.spring: datasource: driver-class-na罪焐芡拂me: com.mysql.jdbc.Driver url: jdbc:mysql://127.0.0.1:3306/test?useunicode=true&characterEncoding=utf8 username: root password: rood
6、接着要告诉springboot你的Mybatis映射关系配置在哪里,就是在yml中写入以下配置:mybatis: type-aliases-package: com.gyf.domain mapper-locations: classpath:mapper/*Mapper.xml
7、接下去就是创建domain包和mapper包,然后写实体类,接口和映射的Mapper.xml,这一块开始就已经是属于mybatis的内容的,在springboot中集成mybatis的部分已经完成了.