1.配置tomcat数据源:

#   数据源基本配置
spring.datasource.url=jdbc:mysql://localhost:3306/shoptest?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#最大等待连接中的数量,设位0则没有限制.
spring.datasource.tomcat.max-idle=10
#最大连接活动数:
spring.datasource.tomcat.max-active=50
#最大等待毫秒数,单位为ms,超过时间会出错误信息:
spring.datasource.tomcat.max-wait=10000
#数据库连接池初始化连接数:
spring.datasource.tomcat.initial-size=5

  1. 配置dbcp2数据源:

#   数据源基本配置
spring.datasource.url=jdbc:mysql://localhost:3306/shoptest?useUnicode=true&characterEncoding=UTF-8
spring.datasource.username=root
spring.datasource.password=root
#指定数据库类型:
spring.datasource.type=org.apache.commons.dbcp2.BasicDataSource
#spring.datasource.driver-class-name=com.mysql.jdbc.Driver
#最大等待连接中的数量,设位0则没有限制.
spring.datasource.dbcp2.max-idle=10
#最大连接活动数:
spring.datasource.dbcp2.max-total=50
#最大等待毫秒数,单位为ms,超过时间会出错误信息:
spring.datasource.dbcp2.max-wait-millis=10000
#数据库连接池初始化连接数:
spring.datasource.dbcp2.initial-size=5

  1. springboot整合Mybatis框架:

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

配置文件:

#mybatis整合:
# 指定全局配置文件位置
mybatis.config-location: classpath:mybatis/mybatis-config.xml
#指定sql存放文件.
mybatis.mapper-locations=classpath:mybatis/mapper/*.xml

#日志配置DEBUG,可以更好的观察测试结果
logging.level.root=DEBUG
logging.level.org.springframework=DEBUG
logging.level.org.mybatis=DEBUG

启动类上设定@MapperScan定义扫描:

@MapperScan(value = "com.account.demo.dao")

 com.account.demo.dao就是dao层

         2.配置mybatis分页插件

.引入jar包:
<!-- 分页插件 -->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.</version>
</dependency>
.配置资源文件:
#mybatis的PageHeader
pagehelper.helperDialect=mysql
pagehelper.reasonable=true
pagehelper.supportMethodsArguments=true
pagehelper.params=count=countSql .重点:
//设置分页信息,分别是当前页数和每页显示的总记录数【记住:必须在mapper接口中的方法执行之前设置该分页信息】
PageHelper.startPage(page, rows);
.例子:
@Override
public PageBean getList(Integer page, Integer rows) {
//设置分页信息,分别是当前页数和每页显示的总记录数【记住:必须在mapper接口中的方法执行之前设置该分页信息】
PageHelper.startPage(page, rows);
List<Item> listData = itemMapper.getList();//会加limit:
int count = itemMapper.getListCount(); //总记录数: PageBean<Item> pageData = new PageBean<>(page, rows, count,listData);
return pageData;
}
分享一个工具类:
package com.account.demo.util; import java.util.List; /**
* 分页插件的Bean:
*/
public class PageBean<T> {
// 当前页
private Integer currentPage = ;
// 每页显示的总条数
private Integer pageSize = ;
// 总条数
private Integer totalNum;
// 是否有下一页
private Integer isMore;
// 总页数
private Integer totalPage;
// 开始索引
private Integer startIndex;
// 分页结果
private List<T> items; public PageBean() {
super();
} public PageBean(Integer currentPage, Integer pageSize, Integer totalNum,List items) {
super();
this.currentPage = currentPage;
this.pageSize = pageSize;
this.totalNum = totalNum;
this.totalPage = (this.totalNum+this.pageSize-)/this.pageSize;
this.startIndex = (this.currentPage-)*this.pageSize;
this.isMore = this.currentPage >= this.totalPage?:;
this.items = items;
} public Integer getCurrentPage() {
return currentPage;
} public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
} public Integer getPageSize() {
return pageSize;
} public void setPageSize(Integer pageSize) {
this.pageSize = pageSize;
} public Integer getTotalNum() {
return totalNum;
} public void setTotalNum(Integer totalNum) {
this.totalNum = totalNum;
} public Integer getIsMore() {
return isMore;
} public void setIsMore(Integer isMore) {
this.isMore = isMore;
} public Integer getTotalPage() {
return totalPage;
} public void setTotalPage(Integer totalPage) {
this.totalPage = totalPage;
} public Integer getStartIndex() {
return startIndex;
} public void setStartIndex(Integer startIndex) {
this.startIndex = startIndex;
} public List<T> getItems() {
return items;
} public void setItems(List<T> items) {
this.items = items;
}
}

 

  1. 其他整合JPA(Hibernate),JDBCTemplate的,等后面的篇章把SpringBoot深入浅出对自己主要内容整理完后,会整理这些知识点,发出来.

(入门SpringBoot)SpringBoot项目数据源以及整合mybatis(二)的更多相关文章

  1. Maven项目中Spring整合Mybatis

    Maven项目中Spring整合Mybatis 添加jar包依赖 spring需要的jar包依赖 <dependency> <groupId>org.springframewo ...

  2. 小D课堂-SpringBoot 2.x微信支付在线教育网站项目实战_3-1.整合Mybatis访问数据库和阿里巴巴数据源

    笔记 1.整合Mybatis访问数据库和阿里巴巴数据源     简介:整合mysql 加入mybatis依赖,和加入alibaba druid数据源 1.加入依赖(可以用 http://start.s ...

  3. java框架之SpringBoot(9)-数据访问及整合MyBatis

    简介 对于数据访问层,无论是 SQL 还是 NOSQL,SpringBoot 默认采用整合 SpringData 的方式进行统一处理,添加了大量的自动配置,引入了各种 Template.Reposit ...

  4. Spring Boot入门系列(六)如何整合Mybatis实现增删改查

    前面介绍了Spring Boot 中的整合Thymeleaf前端html框架,同时也介绍了Thymeleaf 的用法.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/z ...

  5. Spring Boot入门系列(十八)整合mybatis,使用注解的方式实现增删改查

    之前介绍了Spring Boot 整合mybatis 使用xml配置的方式实现增删改查,还介绍了自定义mapper 实现复杂多表关联查询.虽然目前 mybatis 使用xml 配置的方式 已经极大减轻 ...

  6. Spring Boot入门系列(十九)整合mybatis,使用注解实现动态Sql、参数传递等常用操作!

    前面介绍了Spring Boot 整合mybatis 使用注解的方式实现数据库操作,介绍了如何自动生成注解版的mapper 和pojo类. 接下来介绍使用mybatis 常用注解以及如何传参数等数据库 ...

  7. 微信小程序初体验,入门练手项目--通讯录,部署上线(二)

    接上一篇<微信小程序初体验,入门练手项目--通讯录,后台是阿里云服务器>:https://www.cnblogs.com/chengxs/p/9898670.html 开发微信小程序最尴尬 ...

  8. SpringBoot第五篇:整合Mybatis

    作者:追梦1819 原文:https://www.cnblogs.com/yanfei1819/p/10869315.html 版权声明:本文为博主原创文章,转载请附上博文链接! 引言   ORM框架 ...

  9. 如何用IDEA创建springboot(maven)并且整合mybatis连接mysql数据库和遇到的问题

    一.New->Project 二.点击next 三.在Group栏输入组织名,Artifact就是项目名.选择需要的java版本,点击next 四.添加需要的依赖 在这里我们也可以添加sql方面 ...

随机推荐

  1. A*和IDA*介绍

    \(A*\)算法是一种很神奇的搜索方法,它属于启发式搜索中的一种.A*最主要的功能当然就是用来剪枝,提高搜索的效率.A*主要的实现方法是通过一个估价函数,每次对下一步进行一个估价,根据估价出的值来决定 ...

  2. C# 使用Epplus导出Excel [3]:合并列连续相同数据

    C# 使用Epplus导出Excel [1]:导出固定列数据 C# 使用Epplus导出Excel [2]:导出动态列数据 C# 使用Epplus导出Excel [3]:合并列连续相同数据 C# 使用 ...

  3. (14)zabbix Simple checks基本检测

    1. 开始 Simple checks通常用来检查远程未安装代理或者客户端的服务 使用simple checks,被监控客户端无需安装zabbix agent客户端,zabbix server直接使用 ...

  4. java代码解析二维码

    java代码解析二维码一般步骤 本文采用的是google的zxing技术进行解析二维码技术,解析二维码的一般步骤如下: 一.下载zxing-core的jar包: 二.创建一个BufferedImage ...

  5. A Fast and Easy to Use AES Library

    http://www.codeproject.com/Articles/57478/A-Fast-and-Easy-to-Use-AES-Library Introduction EfAesLib i ...

  6. The US in understimating Huawei, says founder Ren zhengfei

    Huawei Founder Ren Zhengfei has downplayed the impact of the US executive order that cripple Huawei' ...

  7. USB storage drivers分析之一

    /drivers/usb/storage/Makefile ## Makefile for the USB Mass Storage device drivers.## 15 Aug 2000, Ch ...

  8. python中join()函数讲解

    本文简述的是string.join(words[, sep]),它的功能是把字符串或者列表,元组等的元素给连接起来,返回一个字符串,和split()函数与正好相反,看下面的代码理解. a=[" ...

  9. HDU 4089 && UVa 1498 Activation 带环的概率DP

    要在HDU上交的话,要用滚动数组优化一下空间. 这道题想了很久,也算是想明白了,就好好写一下吧. P1:激活游戏失败,再次尝试. P2:连接失服务器败,从队首排到队尾. P3:激活游戏成功,队首的人出 ...

  10. 在ubuntu上安装npm

    sudo apt install npm 执行上面的安装命令,会报错: Reading package lists... Done Building dependency tree Reading s ...