文末视频讲解


SpringBoot的版本是2.2.0

一、整合Mybatis

1-1、引入pom文件

  <dependency>     <groupId>mysqlgroupId>     <artifactId>mysql-connector-javaartifactId>     <version>8.0.19version> dependency>  <dependency>     <groupId>com.alibabagroupId>     <artifactId>druid-spring-boot-starterartifactId>     <version>1.1.23version> dependency>  <dependency>     <groupId>org.mybatis.spring.bootgroupId>     <artifactId>mybatis-spring-boot-starterartifactId>     <version>2.1.3version> dependency>

1-2、添加application.yml配置文件

添加MySql配置文件
spring:    datasource:        type: com.alibaba.druid.pool.DruidDataSource        driver-class-name: com.mysql.cj.jdbc.Driver        url: jdbc:mysql://ip:prot/database?useUnicode=true&characterEncoding=utf-8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=UTC        username: root        password: 123456        dbcp2:            min-idle: 5                                 # 数据库连接池最小维持连接数            initial-size: 5                            # 初始连接数            max-total: 5                               # 最大连接数            max-wait-millis: 200                      # 等待链接获取的最大超时时间
添加Mybatis配置文件
mybatis:    type-aliases-package: com.xdx97.frame         # 所有Entity别名类所在包    mapper-locations: classpath:mappers/**/*Mapper.xml      # mapper映射文件 - classpath:mybatis/mapper/**/*.xml

1-3、测试

Frame
public class Frame {    private Integer id;    private String name;    public Integer getId() {        return id;    }    public void setId(Integer id) {        this.id = id;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }}
TestMapper
import com.xdx97.frame.bean.Frame;import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Param;@Mapperpublic interface TestMapper{    Frame selectById(@Param("idq") int id);}
TestMapper.xml
<?xml version="1.0" encoding="UTF-8"?>        <mapper namespace="com.xdx97.frame.mapper.TestMapper"><select id="selectById" parameterType="java.lang.Integer" resultType="com.xdx97.frame.bean.Frame">        SELECT id,name FROM frame WHERE id = #{idq}    select>mapper>
TestController
import com.xdx97.frame.bean.Frame;import com.xdx97.frame.mapper.TestMapper;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.web.bind.annotation.GetMapping;import org.springframework.web.bind.annotation.RestController;@RestControllerpublic class TestController {        @Autowired    private TestMapper testMapper;    @GetMapping("/test")    public Frame fun(){        return testMapper.selectById(1);    }}

二、整合Mybatis-Plus

2-1、引入pom

  <dependency>     <groupId>com.baomidougroupId>     <artifactId>mybatis-plus-boot-starterartifactId>     <version>3.2.0version> dependency>

2-2、修改yml文件

mybatis:  type-aliases-package: com.xdx97.frame         # 所有Entity别名类所在包mybatis-plus:  mapper-locations: classpath:mappers/**/*Mapper.xml      # mapper映射文件 - classpath:mybatis/mapper/**/*.xml
2-3、修改TestMapper

继承BaseMapper

import com.baomidou.mybatisplus.core.mapper.BaseMapper;import com.xdx97.frame.bean.Frame;import org.apache.ibatis.annotations.Mapper;import org.apache.ibatis.annotations.Param;@Mapperpublic interface TestMapper extends BaseMapper {    Frame selectById(@Param("idq") int id);}

这样,baseMapper里面的方法我们就可以直接使用了

三、其它

3-1、如果你需要用到枚举,那么你需要多配置一个handle

配置位置如下,具体handle如果写,百度一下

mybatis-plus:  mapper-locations: classpath:mappers/**/*Mapper.xml      # mapper映射文件 - classpath:mybatis/mapper/**/*.xml  type-handlers-package:
3-2、如果引入Mbatis-Plus后出现了如下异常
Invalid bound statement (not found):

如果你的xml等一些配置关联没有写错的话,那么请考虑下面这种情况

  • 如果引用mybatis-plus-boot-starter 依赖,需要配置 mybatis-plus.mapper-locations

  • 如果引用mybatis-plus 依赖,需要配置 mybatis.mapper-locations


springboot 整合mybatis_SpringBoot整合Mybatis、MybatisPuls相关推荐

  1. springboot 整合mybatis_SpringBoot整合MyBatis框架快速入门

    MyBatis概述: mybatis是一个优秀的基于java的持久层框架,它内部封装了jdbc,使开发者只需要关注sql语句本身,而不需要花费精力去处理加载驱动.创建连接.创建statemenet等繁 ...

  2. SpringBoot 实战 (九) | 整合 Mybatis

    微信公众号:一个优秀的废人 如有问题或建议,请后台留言,我会尽力解决你的问题. 前言 如题,今天介绍 SpringBoot 与 Mybatis 的整合以及 Mybatis 的使用,本文通过注解的形式实 ...

  3. SpringBoot实战:整合Redis、mybatis,封装RedisUtils工具类等(附源码)

    创建SpringBoot项目 在线创建方式 网址:https://start.spring.io/ 然后创建Controller.Mapper.Service包 SpringBoot整合Redis 引 ...

  4. 玩转 SpringBoot 2.x 整合 Mybatis

    前言 MyBatis 是一款优秀的持久层框架,它支持定制化 SQL.存储过程以及高级映射.MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集.MyBatis 可以使用简单的 ...

  5. 利用IDEA搭建SpringBoot项目,整合mybatis,实现简单的登录功能。

    利用IDEA搭建SpringBoot项目,整合mybatis,实现简单的登录功能. 仅供参考!!! 仅供参考!!! 仅供参考!!! 利用闲余时间想自己搭建一个springboot+mybatis的项目 ...

  6. SpringBoot实战:整合Redis、mybatis,封装RedisUtils工具类等

    创建SpringBoot项目 在线创建方式 网址:https://start.spring.io/ 然后创建Controller.Mapper.Service包 SpringBoot整合Redis 引 ...

  7. JWT 教程_1 SpringBoot与JWT整合

    https://gitee.com/fakerlove/spring-security 文章目录 1. 介绍 2. SpringBoot与JWT整合 2.1 JWT的结构: 2.2 JWT的使用测试: ...

  8. docker 安装clickhouse(springboot mybatisplus clickhouse 整合)

    1.命令直接安装 docker run -d --name ch-server --ulimit nofile=262144:262144 -p 8123:8123 -p 9000:9000 -p 9 ...

  9. 《Activiti/Flowable  深入BPM工作流》- Activiti 与springboot 怎么进行整合?

    <Activiti/Flowable  深入BPM工作流> -Activiti 与springboot 怎么进行整合? 一.问题 Activiti 如何与springboot进行整合? 1 ...

最新文章

  1. 精选SpringBoot+Vue开发的开源系统(前端+后端+小程序)
  2. python numpy筛选 总数
  3. 笔记本自开wifi设置
  4. Java中获取Date的昨天代码实现
  5. Redis配置文件常用配置详解
  6. html手机pc不同页面,PC端和手机端如何同时生成静态页
  7. Nacos客户端配置
  8. html表单提交后怎么发送邮箱,Dreamweaver中用表单制作了留言板,如何将内容提交后发到指定邮箱?...
  9. python饼状图教程_Python数据可视化:饼状图的实例讲解
  10. 《那些年啊,那些事——一个程序员的奋斗史》——63
  11. java怎么将程序保存在桌面_在Java桌面应用程序中保留数据的最佳方法是什么?...
  12. 我的编程能力是从什么时候开始突飞猛进的?
  13. 【译文 Part 1】NEO vs. ETH--为什么NEO可能是2018最强数字货币?
  14. 为什么要玩FLTK(Fast Light Tool Kit)
  15. oracle rman异地备份,rman异地备份与恢复测试
  16. spring框架对jdk版本要求
  17. 英雄联盟一直连接服务器win10,手把手修复win10系统英雄联盟连接不上服务器的解决方法...
  18. c++语言里平方根值函数,函数式编程之函数定义与使用(以scala语言为例)
  19. 1分钟了解 rap2
  20. webuploader+上传文件夹

热门文章

  1. mysql 导入百万级数据 几种 java_Java 修行第034天--执行计划及其使用--Oracle数据导入导出--第三章MySQL使用...
  2. linux vps 命令,CentOS最常用Linux vps操作命令整理大全
  3. PDF.js如何添加放大缩小的功能,转换成图片应该如何实现?
  4. Python 文件读写
  5. js 判断一个字符在字符串中出现的次数
  6. So Easy! 让开发人员更轻松的工具和资源
  7. JS之setTimeOut与clearTimeOut
  8. 页面重构-让我们的布局自适应
  9. 转载 300年前的黑色“巫女”
  10. Netty中的策略者模式