(1)新建一个SpringBoot工程,在pom.xml中配置相关jar依赖

贴代码:

 <!--加载mybatis整合springboot-->
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.3.1</version>
</dependency>
<!--MySQL的jdbc驱动包-->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>

(2)在SpringBoot的核心配置文件application.properties中配置数据源

需要注意的是6.0以上的驱动连接字符串为 com.mysql.cj.jdbc.Driver  比之前多了一个cj

贴代码:
spring.datasource.username=root
spring.datasource.password=root
#6.0以上的驱动连接字符串为 com.mysql.cj.jdbc.Driver 比之前多了一个cj
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
spring.datasource.url=jdbc:mysql://localhost:3306/student?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT
大家自己创建Model Mapper dao层 写好代码,这里我就不自己写了,我自动生成一下!


导入GeneratorMapper.xml文件,按照文件内的注释修改配置参数(省略)
在pom文件里面配置自动生成插件


生成完毕
编写Service层  Controller层 
错误级别调节:

Controller层如下

mapper如下:

这里需要添加一个注解   @Mapper    //把该mapper接口变成spring容器中的一个bean

运行测试:

以上到此为止

补充:

上面的项目接口StudentMapper类和StudentMapper.xml是在同一个包下的,如果不在同一个包如何处理?

如图:

那么我们就需要在application里面指定mapper.xml的位置

#指定mapper.xml的位置
mybatis.mapper-locations=classpath:mapper/*.xml

SpringBoot(九):SpringBoot集成Mybatis的更多相关文章

  1. SpringBoot(九)_springboot集成 MyBatis

    MyBatis 是一款标准的 ORM 框架,被广泛的应用于各企业开发中.具体细节这里就不在叙述,大家自行查找资料进行学习下. 加载依赖 <dependency> <groupId&g ...

  2. SpringBoot系列之集成Mybatis教程

    SpringBoot系列之集成Mybatis教程 环境准备:IDEA + maven 本博客通过例子的方式,介绍Springboot集成Mybatis的两种方法,一种是通过注解实现,一种是通过xml的 ...

  3. SpringBoot学习之集成mybatis

    一.spring boot集成Mybatis gradle配置: //gradle配置: compile("org.springframework.boot:spring-boot-star ...

  4. springboot 零xml集成mybatis

    maven依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="htt ...

  5. SpringBoot(九) -- SpringBoot与数据访问

    一.简介 对于数据访问层,无论是SQL还是NOSQL,Spring Boot默认采用整合Spring Data的方式进行统一处理,添加大量自动配置,屏蔽了很多设置.引入各种xxxTemplate,xx ...

  6. springboot之集成mybatis mongo shiro druid redis jsp

    闲来无事,研究一下spingboot  发现好多地方都不一样了,第一个就是官方默认不支持jsp  于是开始狂找资料  终于让我找到了 首先引入依赖如下: <!-- tomcat的支持.--> ...

  7. springboot集成mybatis(二)

    上篇文章<springboot集成mybatis(一)>介绍了SpringBoot集成MyBatis注解版.本文还是使用上篇中的案例,咱们换个姿势来一遍^_^ 二.MyBatis配置版(X ...

  8. springboot集成mybatis(一)

    MyBatis简介 MyBatis本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation迁移到了google code,并且改名为MyB ...

  9. SpringBoot 集成Mybatis 连接Mysql数据库

    记录SpringBoot 集成Mybatis 连接数据库 防止后面忘记 1.添加Mybatis和Mysql依赖 <dependency> <groupId>org.mybati ...

随机推荐

  1. mac外接键盘HOME,END键问题

    参考: How to Fix the Home and End Buttons for an External Keyboard in Mac mac老用户应该都知道, MAC自带的键盘的 cmd+左 ...

  2. 使用TCP发送文件

    客户端 package com.zy.demo3; import java.io.File; import java.io.FileInputStream; import java.io.IOExce ...

  3. Codeforces Round #646 (Div. 2) E. Tree Shuffling(树上dp)

    题目链接:https://codeforces.com/contest/1363/problem/E 题意 有一棵 $n$ 个结点,根为结点 $1$ 的树,每个结点有一个选取代价 $a_i$,当前 $ ...

  4. zjnu1757Excellent (数学公式)

    Description Let us begin with a positive integer N and find the smallest positive integer which does ...

  5. JavaScript——DOMM

    文本节点 != 文本内容

  6. Ancient Printer HDU - 3460 贪心+字典树

    The contest is beginning! While preparing the contest, iSea wanted to print the teams' names separat ...

  7. Selenium和ChromeDriver下载地址

    Selenium 官方所有版本: https://selenium-release.storage.googleapis.com/index.html 镜像所有版本:https://npm.taoba ...

  8. Linunx系统引导过程及MBR/GRUB故障

    Linunx系统引导过程 系统初始化进程 init进程 Systemd Systemd单元类型 允许级别所对应的systemd目标 修复MBR扇区故障 解决思路 操作 修复GRUB引导故障 解决思路 ...

  9. Python——处理CSV、PDF文件

    一.CSV文件处理 (1)读取 import csv filename = "E:/GitHub/Python-Learning/LIVE_PYTHON/2018-06-05/学位英语成绩合 ...

  10. Hexo-域名设置+收录

    Hexo-域名设置+Github域名加速+网址收录 Github.Gitee绑定域名,然后进行网址收录. 不想购买域名也完全可以进行网址收录. 购买阿里云域名 1.进入阿里云域名网站 2.进入价格详情 ...