springboot如何整合mybatis

百度搜索:mavenRepo 这是maven的仓库,在这里可以自己想要的依赖。

1.springboot 整合mybatis 需要哪些依赖包

【mybatis,jdbc,数据源驱动】

1.1.mybatis

<!--spring整合mybatis   -->
<dependency>
	<groupId>org.mybatis.spring.boot</groupId>
	<artifactId>mybatis-spring-boot-starter</artifactId>
	<version>2.2.0</version>
</dependency>

1.2.jdbc

<!--springBoot数据库连接,jdbc链接包  -->
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-jdbc</artifactId>
</dependency>

1.3.数据源驱动

<!--引入数据库驱动 -->
<dependency>
	<groupId>mysql</groupId>
	<artifactId>mysql-connector-java</artifactId>
	<scope>runtime</scope>
	<!-- <version>5.1.32</version> 去掉版本,则会使用springboot自己维护的版本 -->
</dependency>

2.实现mybatis的调用的步骤

1.主启动类 @SpringBootApplication @SpingApplication
2.编辑pojo @Data @Accessors(chain=true)
3.mapper接口 interface
4.测试类 @SpringBootTest @Test
5.映射文件 位置:resources/mappers/ id=方法名,namespace=接口的路径(全路径),resultType=返回类型(全路径),resultMap(单表,多表联查)
6.yml配置 端口,spring整合数据源,mybatis

server:
  port: 端口

#spring整合数据源 最快的数据源
spring:
  datasource:
    #使用高版本驱动时使用cj
    #serverTimezone=GMT%2B8   东8%2B +号
    #&useUnicode=true&characterEncoding=utf8 是否开启unicode编码/utf-8
    #&autoReconnect=true  断线是否重连
    #&allowMultiQueries=true 是否允许批量操作
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.0.1:3306/库名?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf8&autoReconnect=true&allowMultiQueries=true
    username: root
    #如果密码以数字0开头,则使用""号包裹  "0123456"
    password: root

#SpringBoot整合Mybatis配置
mybatis:
  #设置别名包
  type-aliases-package: 包路径
  #加载映射文件
  mapper-locations: classpath:/mappers/*.xml
  #开启驼峰映射
  configuration:
    map-underscore-to-camel-case: true
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值