springboot使用依赖包配置mybatis(^_^)

本文介绍了如何在SpringBoot应用中使用MyBatis-Spring-Boot-Starter进行快速配置,包括自动创建SqlSessionFactoryBean和SqlSessionTemplate,自动扫描Mapper并注册到Spring上下文。同时提到了配置数据源、application.properties中的mybatis参数、Mapper接口的@Mapper注解以及mapper-locations的使用场景。总结了配置数据源、设置数据库连接参数、扫描Mapper接口和启用注解扫描的步骤。
摘要由CSDN通过智能技术生成

 

首先来谈谈这个依赖包

mybatis开发团队为Spring Boot 提供了 MyBatis-Spring-Boot-Starter 

首先,MyBatis-Spring-Boot-Starter will:

  • Autodetect an existing DataSource.
  • Will create and register an instance of a SqlSessionFactoryBean passing that DataSource as an input.
  • Will create and register an instance of a SqlSessionTemplate got out of the SqlSessionFactoryBean.
  • Autoscan your mappers, link them to the SqlSessionTemplate and register them to Spring context so they can be injected into your beans.

    来源: http://www.mybatis.org/spring-boot-starter/mybatis-spring-boot-autoconfigure/index.html

就是说,使用了该Starter之后,只需要定义一个DataSource即可,它会自动创建使用该DataSource的SqlSessionFactoryBean以及SqlSessionTemplate。会自动

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值