(1)、添加依赖

         <dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.0.0</version>
</dependency>

(2)、编写Mapper接口类

 package cn.coreqi.mapper;

 import cn.coreqi.entities.User;
import org.apache.ibatis.annotations.Mapper; @Mapper
public interface UserMapper { public User getUserById(Integer id); public int addUser(User user); public int modifyUser(User user); public int delUserById(Integer id);
}

(3)、编写Mybatis配置文件

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration
PUBLIC "-//mybatis.org//DTD Config 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
<settings>
<setting name="mapUnderscoreToCamelCase" value="True"/>
</settings>
</configuration>

(4)、编写Mapper接口对应的Mapper配置文件

 <?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.coreqi.mapper.UserMapper">
<select id="getUserById" resultType="cn.coreqi.entities.User">
select * from users where Id = #{id}
</select> <insert id="addUser" useGeneratedKeys="true" keyProperty="Id">
insert into users(UserName,PassWord,Enabled) values(#{UserName},#{PassWord},#{Enabled})
</insert> <update id="modifyUser">
update users set UserName = #{UserName},PassWord = #{PassWord},Enabled = #{Enabled} where Id = #{Id}
</update> <delete id="delUserById">
delete from users where Id = #{id}
</delete>
</mapper>

(5)、在配置文件中配置mybatis

 spring.datasource.username=root
spring.datasource.password=123456
spring.datasource.url=jdbc:mysql://localhost:3306/JdbcDemo?serverTimezone=UTC
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.type=com.alibaba.druid.pool.DruidDataSource mybatis.config-location=classpath:mybatis/mybatis-config.xml
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

SpringBoot整合MyBatis(XML)的更多相关文章

  1. SpringBoot整合Mybatis之xml

    SpringBoot整合Mybatis mybatis ORM框架.几个重要的概念: Mapper配置 : 可以使用基于XML的Mapper配置文件来实现,也可以使用基于Java注解的Mybatis注 ...

  2. SpringBoot 整合 Mybatis + Mysql——XML配置方式

    一.介绍 SpringBoot有两种方法与数据库建立连接,一种是集成Mybatis,另一种用JdbcTemplate,本文主要讨论集成Mybatis方式. SpringBoot整合Mybatis也有两 ...

  3. springboot整合mybatis时无法读取xml文件解决方法(必读)

    转    http://baijiahao.baidu.com/s?id=1588136004120071836&wfr=spider&for=pc 在springboot整合myba ...

  4. SpringBoot整合Mybatis之项目结构、数据源

    已经有好些日子没有总结了,不是变懒了,而是我一直在奋力学习springboot的路上,现在也算是完成了第一阶段的学习,今天给各位总结总结. 之前在网上找过不少关于springboot的教程,都是一些比 ...

  5. SpringBoot整合Mybatis【非注解版】

    接上文:SpringBoot整合Mybatis[注解版] 一.项目创建 新建一个工程 ​ 选择Spring Initializr,配置JDK版本 ​ 输入项目名 ​ 选择构建web项目所需的state ...

  6. springboot学习随笔(四):Springboot整合mybatis(含generator自动生成代码)

    这章我们将通过springboot整合mybatis来操作数据库 以下内容分为两部分,一部分主要介绍generator自动生成代码,生成model.dao层接口.dao接口对应的sql配置文件 第一部 ...

  7. springboot整合mybatis出现的一些问题

    springboot整合mybatis非常非常的简单,简直简单到发指.但是也有一些坑,这里我会详细的指出会遇到什么问题,并且这些配置的作用 整合mybatis,无疑需要mapper文件,实体类,dao ...

  8. springBoot整合mybatis、jsp 或 HTML

    springBoot整合mybatis.jsp Spring Boot的主要优点: 1:  为所有Spring开发者更快的入门: 2:  开箱即用,提供各种默认配置来简化项目配置: 3:  内嵌式容器 ...

  9. SpringBoot系列七:SpringBoot 整合 MyBatis(配置 druid 数据源、配置 MyBatis、事务控制、druid 监控)

    1.概念:SpringBoot 整合 MyBatis 2.背景 SpringBoot 得到最终效果是一个简化到极致的 WEB 开发,但是只要牵扯到 WEB 开发,就绝对不可能缺少数据层操作,所有的开发 ...

随机推荐

  1. servlet表单中get和post方法的区别

    Form中的get和post方法,在数据传输过程中分别对应了HTTP协议中的GET和POST方法.二者主要区别如下: 1.Get是用来从服务器上获得数据,而Post是用来向服务器上传递数据. 2.Ge ...

  2. MT【239】离心率最大

    已知点$A$为椭圆$\dfrac{x^2}{a^2}+\dfrac{y^2}{b^2}=1(a>b>0)$的左顶点,$O$为坐标原点,过椭圆的右焦点$F$作垂直于$x$轴的直线$l$.若直 ...

  3. MT【39】构造二次函数证明

    这种构造二次函数的方法最早接触的应该是在证明柯西不等式时: 再举一例: 最后再举个反向不等式的例子: 评:此类题目的证明是如何想到的呢?他们都有一个明显的特征$AB\ge(\le)C^2$,此时构造二 ...

  4. iOS 【终极方案】精准获取webView内容高度,自适应高度

    前言:是这样的,刚写完上一篇文章还没缓过神来,上一篇文章我还提到了,想和大家聊聊原生+H5如何无缝连接的故事.结果我朋友就给我发了两篇他的作品.他的做法也都有独到之处.好的文章都是这样,让你每次看都能 ...

  5. 自学Zabbix12.3 Zabbix命令-zabbix_agentd

    点击返回:自学Zabbix之路 点击返回:自学Zabbix4.0之路 点击返回:自学zabbix集锦 自学Zabbix12.3 Zabbix命令-zabbix_agentd 1. zabbix_age ...

  6. 使用nagios监控ssl证书过期时间

    1.编写监控脚本. # vim check_ssl_expiry.sh #!/bin/bash STATE_OK=0 STATE_WARNING=1 STATE_CRITICAL=2 Host=$1 ...

  7. SDL OPENGL 在linux ubuntu示例

    gl画纹理texture /* * SDL OpenGL Tutorial. * (c) Michael Vance, 2000 * briareos@lokigames.com * * Distri ...

  8. Node.js npm uuid

    nodejs 提供了一个 node-uuid 模块用于生成 uuid 使用方法为 const uuidV1 = require('uuid/v1'); uuidV1(); 或者为 const uuid ...

  9. MATLAB:图像裁切(imcrop函数)

    对图像进行裁切可用imcrop函数,实现过程如下: close all; %关闭当前所有图形窗口,清空工作空间变量,清除工作空间所有变量 clear all; clc; [A,map]=imread( ...

  10. C#使用Ado.Net读写数据库

    1.使用DataReader方式读取资料 [csharp] view plain copy String connString = ConfigurationManager.ConnectionStr ...