个人博客网:https://wushaopei.github.io/    (你想要这里多有)

1.增加持久化层

		<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid</artifactId>
<version>1.0.5</version>
</dependency>
<dependency>
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>1.1.1</version>
</dependency>

2.Mapper相关

实体类

public class Emp {

	private Integer empId;
private String empName;
private Integer empAge;

数据库表

CREATE TABLE `table_emp` (
`emp_id`  int NOT NULL AUTO_INCREMENT ,
`emp_name`  varchar(100) NULL ,
`emp_age`  int NULL ,
PRIMARY KEY (`emp_id`)
)

Mapper配置文件

<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.atguigu.springboot.mappers.EmpMapper">
<select id="selectAll" resultType="com.atguigu.springboot.bean.Emp">
select emp_id empId, emp_name empName, emp_age empAge
from table_emp
</select>
</mapper>

Mapper接口

public interface EmpMapper {

	List<Emp> selectAll();

}

Service接口

@Transactional
public interface EmpService { List<Emp> getAll(); }

Service 接口实现

@Service
public class EmpServiceImpl implements EmpService { @Autowired
private EmpMapper empMapper; @Override
public List<Emp> getAll() {
return empMapper.selectAll();
} }

Handler调用

@Autowired
private EmpService empService; @ResponseBody
@RequestMapping("/getAll")
public List<Emp> getAll() {
return empService.getAll();
}

3.增加application.yml配置

spring:
datasource:
name: mydb
type: com.alibaba.druid.pool.DruidDataSource
url: jdbc:mysql://127.0.0.1:3306/sb_db
username: root
password: root
driver-class-name: com.mysql.jdbc.Driver
mybatis:
mapper-locations: classpath*:/mybatis/*Mapper.xml

4.在主启动类上使用注解扫描Mapper

@MapperScan("com.webcode.springboot.mappers")

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

  1. SpringBoot学习笔记(三):SpringBoot集成Mybatis、SpringBoot事务管理、SpringBoot多数据源

    SpringBoot集成Mybatis 第一步我们需要在pom.xml里面引入mybatis相关的jar包 <dependency> <groupId>org.mybatis. ...

  2. SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版)

    SpringBoot Mybatis整合(注解版),SpringBoot集成Mybatis(注解版) ================================ ©Copyright 蕃薯耀 2 ...

  3. SpringBoot集成Mybatis并具有分页功能PageHelper

    SpringBoot集成Mybatis并具有分页功能PageHelper   环境:IDEA编译工具   第一步:生成测试的数据库表和数据   SET FOREIGN_KEY_CHECKS=0;   ...

  4. SpringBoot集成MyBatis底层原理及简易实现

    MyBatis是可以说是目前最主流的Spring持久层框架了,本文主要探讨SpringBoot集成MyBatis的底层原理.完整代码可移步Github. 如何使用MyBatis 一般情况下,我们在Sp ...

  5. springboot集成mybatis(二)

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

  6. springboot集成mybatis(一)

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

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

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

  8. Springboot集成mybatis(mysql),mail,mongodb,cassandra,scheduler,redis,kafka,shiro,websocket

    https://blog.csdn.net/a123demi/article/details/78234023  : Springboot集成mybatis(mysql),mail,mongodb,c ...

  9. BindingException: Invalid bound statement (not found)问题排查:SpringBoot集成Mybatis重点分析

    重构代码,方法抛出异常:BindingException: Invalid bound statement (not found) 提示信息很明显:mybatis没有提供某方法 先不解释问题原因和排查 ...

  10. SpringBoot集成Mybatis配置动态数据源

    很多人在项目里边都会用到多个数据源,下面记录一次SpringBoot集成Mybatis配置多数据源的过程. pom.xml <?xml version="1.0" encod ...

随机推荐

  1. 一个数number的n次幂 python的pow函数

    @ 目录 解法1:暴力法 解法2:根据奇偶幂分类(递归法,迭代法,位运算法) 实现 pow(x, n),即计算 x 的 n 次幂函数.其中n为整数. 链接: pow函数的实现--leetcode. 解 ...

  2. 心路历程-安装Docker

    心路历程-安装Docker 本机环境 Windows10 激活HyperV功能 新建CentOS虚拟机 centos docker安装 由于是新的虚拟机,所以没有docker旧版本的问题,不需要卸载旧 ...

  3. Day_14【IO流】扩展案例3_对文本文件中的字符串内容进行反转

    分析以下需求,并用代码实现 项目根路径下有text.txt文件,内容如下 我爱黑马 123456 利用IO流的知识读取text.txt文件的内容反转后写入text.txt文件中 654321 马黑爱我 ...

  4. JS导出页面为PDF文件,该如何操作?来看一眼就明白啦!

    1.资源文件或依赖 <script type="text/javascript" src="./js/canvg2.js"></script& ...

  5. Java并发编程(04):线程间通信,等待/通知机制

    本文源码:GitHub·点这里 || GitEE·点这里 一.概念简介 1.线程通信 在操作系统中,线程是个独立的个体,但是在线程执行过程中,如果处理同一个业务逻辑,可能会产生资源争抢,导致并发问题, ...

  6. Centos7 下代理配置

    对于提供服务的服务器来说,一般都配置在内网环境中,而在内网下公司处于安全的考虑,一般不开放外网的访问权限.这时如果想要访问外网,一般需要配置公司提供的代理服务器再进行使用.下面介绍几种配置代理的方法: ...

  7. MySQL数据库基础操作语句

    SQL语言主要用于存取数据.查询数据.更新数据和管理关系数据库系统,分为3种类型: 1.DDL语句 数据库定义语言: 数据库.表.视图.索引.存储过程,例如CREATE DROP ALTER 2.DM ...

  8. Linux系统rabbitmq安装

    rabbitmq消息队列(Message Queue)是一种应用间的通信方式,消息发送后可以立即返回,由消息系统来确保消息的可靠传递.消息发布者只管把消息发布到 MQ 中而不用管谁来取,消息使用者只管 ...

  9. 使用phoenix踩的坑与设计思考

    本文主要介绍在压测HBase的二级索引phoenix时踩的一个坑,使用时需要特别注意,而且背后的原因也很有意思,可以看出HBase和Phoenix对元数据设计上的差异. 1.问题介绍 在做phoeni ...

  10. 启动独立的tomcat服务器,没有自动创建ServletContext,对Context生命周期的监听失败

    1.可能web.xml文件里对ContextListener没有进行配置 2.web.xml文件有关对ContextListener的配置,出现了错误的单词拼写问题 比如 <listener&g ...