SpringBoot - 整合Mybatis和SpringBoot

背景

mybatis整个spring时,需要一个mybatis-spring包

mybatis整个springboot时,需要一个mybatis-spring-boot-starter包

 

 

整合步骤

1-创建项目,勾选组件

 

 

2-配置数据库

 

测试DB配置是否正确:可以直接@Autowire 一个Datasource类

 

 

3-添加pojo, mapper接口,mapper.xml

添加pojo:

 

 定义mapper接口:

注意这里的@Mapper, @Repository

 

 

 

 定义mapper.xml:

 

 

 为了避免在mapper.xml里写全路径名,application.properties这里增加设置:

 

4-添加controller

 

 

posted on 2020-12-07 18:03  frank_cui  阅读(83)  评论(0编辑  收藏  举报

导航

levels of contents