Python 官方文档:入门教程 => 点击学习
PageHelper mybatis的执行流程 mybatis中首先要在配置文件中配置一些东西然后根据这些配置去创建一个会话工厂再根据会话工厂创建会话,会话发出操作数据库的sql语
PageHelper mybatis的执行流程
这就是整个mybatis框架的执行情况。
它主要作用在Executor执行器与mappedeStatement之间
也就是说mybatis可以在插件中获得要执行的sql语句
在sql语句中添加limit语句,然后再去对sql进行封装,从而可以实现分页处理。
引入依赖
<!--分页插件 pagehelper -->
<dependency>
<groupId>com.GitHub.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<!-- 特别注意版本问题 -->
<version>1.2.13</version>
</dependency>
<dependency>
<groupId>Mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.18</version>
</dependency>
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.3.1</version>
</dependency>
yaml配置
#整合数据源
spring:
datasource:
driver-class-name: com.mysql.cj.jdbc.Driver
username: root
passWord: ok
url: jdbc:mysql://localhost:3306/mall?useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8
#Mybatis-Plus的配置
mybatis-plus:
configuration:
log-impl: org.apache.ibatis.logging.stdout.StdOutImpl # 配置在控制台打印 sql语句
# 配置自定义sql语句的 *mapper.xml 文件位置
mapper-locations: classpath:**/mapper/**.xml
pagehelper:
helperDialect: mysql
reasonable: true
supportMethodsArguments: true
params: count=countSql
项目示例结构
CateGoryDao
因为使用了MybatisPlus所以有些方法可以不去实现,通过Plus自己编写
@Mapper
public interface CategoryDao extends BaseMapper<Category> {
}
CateService接口
import cn.pojo.Category;
import java.util.*;
public interface CateService {
public List<Category> pageSelect(int page,int col);
}
CateServiceImple实现
import javax.annotation.Resource;
import java.util.List;
@Service
public class CateServiceImple implements CateService {
@Resource
CategoryDao categoryDao;
@Override
public List<Category> pageSelect(int page, int col) {
// 使用分页表明,从第几页开始,一页多少条数据
PageHelper.startPage(page,col);
// 使用Plus进行查询所有,因为PageHelper插件会进行sql的limit的拼接
List<Category> categories = categoryDao.selectList(null);
return categories;
}
}
核心代码
// 使用分页表明,从第几页开始,一页多少条数据
PageHelper.startPage(page,col);
// 使用Plus进行查询所有,因为PageHelper插件会进行sql的limit的拼接
List<Category> categories = categoryDao.selectList(null);
查看结果
到此这篇关于Mybatis的PageHelper的文章就介绍到这了,更多相关Mybatis的PageHelper内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!
--结束END--
本文标题: Mybatis中的PageHelper的执行流程分析
本文链接: https://www.lsjlt.com/news/140748.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0