SpringBoot整合Mybaitis-使用mapper注解

本文介绍如何在SpringBoot项目中整合Mybatis并利用Mapper注解进行操作。从数据库配置、依赖添加、实体类、Mapper、Service到Controller的编写步骤详细展开,并针对可能出现的问题SLF4J报错提供了解决方案和参考资料。
摘要由CSDN通过智能技术生成

上一篇博文已经详细介绍了SpringBoot环境搭建过程,这一节介绍一下SpringBoot整合Mybatis。

SpringBoot整合Mybatis

方式1:mapper使用注解

项目结构

1:准备数据库数据和配置数据源

#数据源必填项

spring.datasource.driver-class-name= com.mysql.jdbc.Driver

spring.datasource.url = jdbc:mysql://localhost:3306/study?useUnicode=true&characterEncoding=utf-8

spring.datasource.username = root

spring.datasource.password = 123456

 

#选填

# Number of ms to wait before throwing an exception if no connection is available.

spring.datasource.tomcat.max-wait=10000

# Maximum number of active connections that can be allocated from this pool at the same time.

spring.datasource.tomcat.max-active=50

# Validate the connection before borrowing it from the pool.

spring.datasource.tomcat.test-on-borrow=true

 

2:加maven依赖

          <!-- Spring-Mybatis -->

          <dependency>

               <groupId>org.mybatis.spring.boot</groupId>

               <artifactId>mybatis-spring-boot-starter</artifactId>

               <version>1.3.2</version>

          </dependency>

          <!-- MySQL驱动 -->

          <dependency>

               <groupId>mysql</groupId>

               <artifactId>

  • 3
    点赞
  • 23
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值