SpringBoot-注解方式整合Mybatis

本文介绍了如何在SpringBoot应用中通过注解方式整合Mybatis,包括创建Mapper接口,使用Mybatis注解,配置日志以及进行日志测试。
摘要由CSDN通过智能技术生成

SpringBoot整合Mybatis

一.注解方式整合Mybatis

1.创建Air的Mapper接口

@ComponentScan
public interface AirMapper {

    List<Air> selectAll(); 

    Air selectOneById(Integer id);
}

2.添加Mybatis注解

针对增删改查:@Insert,@Delete,@Update,@Select

还是需要在启动类中添加@MapperScan注解

@ComponentScan
public interface AirMapper {

    @Select("select * from air where id =#{id}")
    Air selectOneById(@Param("id") Integer id);
}

3.配置日志

// yml文件
logging:
  level:
    XXX.mapper: DEBUG

# 连接数据库的信息
spring:
  datasource:
    driver-class-name: com.mysql.jdbc.Driver
    url: jdbc:mysql:///air
    username: root
    password
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值