如果你在创建SpringBoot3项目时没有选择Mybatis依赖的话,需要在pom.xml中加入以下的依赖
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
配置mybatis实体和xml映射

XML
# 配置mybatis实体和xml映射
mybatis:
## 映射xml
mapper-locations: classpath:mapper/*.xml
configuration:
# 配置日志
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
map-underscore-to-camel-case: true
告诉Springboot如何扫描mapper包(路径可以按照下图方式找到,别忘记把中间的/替换成.)


创建Service并且标注为Springboot里面的一个bean

别忘了安装MyBatisX插件

准备工作做好,测试一下
controller层代码(访问的时候,后面加/employee/selectAll)

service层

mapper接口层


写好代码后,进行测试访问 http://localhost:9090/employee/selectAll
