MyBatis的三种分页方式,你用过几种?

MyBatis使用篇(十一)—— MyBatis实现分页 文章目录1、搭建演示环境1.1 创建数据表1.2 创建实体类1.3 创建接口Dao1.4 创建SQL映射文件1.5 创建测试类2、通过List结果集实现分页2.1 添加接口方法2.2 添加SQL标签2.3 添加测试方法3、通过SQL参数实现分页3.1 添加接口方法3.2 添加SQL标签3.3 添加测试方法4、通过RowBounds实现分页4.1 添加接口方法4.2 添加SQL标签4.3 添加测试方... 阅读详情

前言

分页是我们在开发中绕不过去的一个坎!当你的数据量大了的时候,一次性将所有数据查出来不现实,所以我们一般都是分页查询的,减轻服务端的压力,提升了速度和效率!也减轻了前端渲染的压力!

注意:由于 java 允许的最大整数为 2147483647,所以 limit 能使用的最大整数也是 2147483647,一次性取出大量数据可能引起内存溢出,所以在大数据查询场合慎重使用!

一、Limit分页

语法:

limit ${startPos},${pageSize}

在实际项目中我们一般会加上为空为null判断,如下:

<if test="startPos!=null and pageSize!=null">
    limit ${startPos},${pageSize}
</if>

业务层代码:

<select id="getUserInfo1" parameterType="map" resultType="dayu">
    select * from user
    <if test="startPos!=null and pageSize!=null">
        limit ${startPos},${pageSize}
    </if>
</select>
List<User> getUserInfo1(Map<String,Object> map);
@Test
 public void selectUser() {
     SqlSession session = MybatisUtils.getSession();
     UserMapper mapper = session.getMapper(UserMapper.class);
     //这里塞值
      Map<String,Object> parms = new HashMap<>();
      parms.put("startPos","0");
      parms.put("pageSize","5");
     List<User> users = mapper.getUserInfo1(parms);
     for (User map: users){
         System.out.println(map);
    }
     session.close();
}

执行结果:

8a191a68da99280807b3d67c8c699152.png

传入0,10时:

d14efec17311cc04d1ce9a9a455a4ca9.png

总结:

  • limit 0,10;

  • 0 代表从第0条数据开始

  • 10 代表查10条数据

  • 等到第二页的时候就是 limit 10,10;

以此类推!

这些内容其实就时MySQL中的内容,不作再详细讲解了。

二、RowBounds分页(不推荐使用)

RowBounds帮我们省略了limit的内容,我们只需要在业务层关注分页即可!无须再传入指定数据!

但是,这个属于逻辑分页,即实际上sql查询的是所有的数据,在业务层进行了分页而已,比较占用内存,而且数据更新不及时,可能会有一定的滞后性!不推荐使用!

RowBounds对象有2个属性,offset和limit。

  • offset:起始行数

  • limit:需要的数据行数

因此,取出来的数据就是:从第offset+1行开始,取limit行

业务层代码:

@Test
public void selectUserRowBounds() {
    SqlSession session = MybatisUtils.getSession();
    UserMapper mapper = session.getMapper(UserMapper.class);
    // List<User> users = session.selectList("com.dy.mapper.UserMapper.getUserInfoRowBounds",null,new RowBounds(0, 5));
    List<User> users = mapper.getUserInfoRowBounds(new RowBounds(0,5));
    for (User map: users){
        System.out.println(map);
    }
    session.close();
}
List<User> getUserInfoRowBounds(RowBounds rowBounds);
<select id="getUserInfoRowBounds" resultType="dayu">
   select * from user
</select>

执行查看结果:

30cd038f4e7f91c307d2e35d164e15f7.png

三、Mybatis_PageHelper分页插件

官方GitHub地址:

https://github.com/pagehelper/Mybatis-PageHelper

引入jar包

<dependency>
   <groupId>com.github.pagehelper</groupId>
   <artifactId>pagehelper</artifactId>
   <version>5.1.7</version>
</dependency>

配置MyBatis核心配置文件

<plugins>
    <plugin interceptor="com.github.pagehelper.PageInterceptor" />
</plugins>

业务层代码

@Test
public void selectUserPageHelper() {
    SqlSession session = MybatisUtils.getSession();
    UserMapper mapper = session.getMapper(UserMapper.class);
    //第二种,Mapper接口方式的调用,推荐这种使用方式。
    PageHelper.startPage(1, 3);
    List<User> list = mapper.getUserInfo();
    //用PageInfo将包装起来
    PageInfo page = new PageInfo(list);
    for (User map: list){
        System.out.println(map);
    }
    System.out.println("page:---"+page);
    session.close();
}

执行结果

af87dd2dd504b5c3268f3633f0c78632.png

总结:

PageHelper还是很好用的,也是物理分页!

实际上我们一般用第二种比较多:Mapper接口方式的调用

//第一种,RowBounds方式的调用
List<User> list = sqlSession.selectList("x.y.selectIf", null, new RowBounds(0, 10));

//第二种,Mapper接口方式的调用,推荐这种使用方式。
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectIf(1);

//第三种,Mapper接口方式的调用,推荐这种使用方式。
PageHelper.offsetPage(1, 10);
List<User> list = userMapper.selectIf(1);

//第四种,参数方法调用
//存在以下 Mapper 接口方法,你不需要在 xml 处理后两个参数
public interface CountryMapper {
    List<User> selectByPageNumSize(
            @Param("user") User user,
            @Param("pageNum") int pageNum, 
            @Param("pageSize") int pageSize);
}
//配置supportMethodsArguments=true
//在代码中直接调用:
List<User> list = userMapper.selectByPageNumSize(user, 1, 10);

//第五种,参数对象
//如果 pageNum 和 pageSize 存在于 User 对象中,只要参数有值,也会被分页
//有如下 User 对象
public class User {
    //其他fields
    //下面两个参数名和 params 配置的名字一致
    private Integer pageNum;
    private Integer pageSize;
}
//存在以下 Mapper 接口方法,你不需要在 xml 处理后两个参数
public interface CountryMapper {
    List<User> selectByPageNumSize(User user);
}
//当 user 中的 pageNum!= null && pageSize!= null 时,会自动分页
List<User> list = userMapper.selectByPageNumSize(user);

//第六种,ISelect 接口方式
//jdk6,7用法,创建接口
Page<User> page = PageHelper.startPage(1, 10).doSelectPage(new ISelect() {
    @Override
    public void doSelect() {
        userMapper.selectGroupBy();
    }
});
//jdk8 lambda用法
Page<User> page = PageHelper.startPage(1, 10).doSelectPage(()-> userMapper.selectGroupBy());

//也可以直接返回PageInfo,注意doSelectPageInfo方法和doSelectPage
pageInfo = PageHelper.startPage(1, 10).doSelectPageInfo(new ISelect() {
    @Override
    public void doSelect() {
        userMapper.selectGroupBy();
    }
});
//对应的lambda用法
pageInfo = PageHelper.startPage(1, 10).doSelectPageInfo(() -> userMapper.selectGroupBy());

//count查询,返回一个查询语句的count数
long total = PageHelper.count(new ISelect() {
    @Override
    public void doSelect() {
        userMapper.selectLike(user);
    }
});
//lambda
total = PageHelper.count(()->userMapper.selectLike(user));

拓展

//获取第1页,10条内容,默认查询总数count
PageHelper.startPage(1, 10);
List<User> list = userMapper.selectAll();
//用PageInfo对结果进行包装
PageInfo page = new PageInfo(list);
//测试PageInfo全部属性
//PageInfo包含了非常全面的分页属性
assertEquals(1, page.getPageNum());
assertEquals(10, page.getPageSize());
assertEquals(1, page.getStartRow());
assertEquals(10, page.getEndRow());
assertEquals(183, page.getTotal());
assertEquals(19, page.getPages());
assertEquals(1, page.getFirstPage());
assertEquals(8, page.getLastPage());
assertEquals(true, page.isFirstPage());
assertEquals(false, page.isLastPage());
assertEquals(false, page.isHasPreviousPage());
assertEquals(true, page.isHasNextPage());

这种方式十分方便快捷好用!推荐使用!

篇幅有限,不可能所有用法都演示一遍!有兴趣的小伙伴可以自行测试一遍!

悄悄的说,反正我是全部试了一遍,还整合了Spring,加了拦截器测试了!

来源:https://blog.youkuaiyun.com/weixin_43829443

Java使用MyBatis框架分页的5种方式 主要为大家详细介绍了Java使用MyBatis框架分页的5种方式,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 立即下载

相关推荐

ESP32蓝牙配网实战:微信小程序中的blufi协议实现与优化

本文详细介绍了在微信小程序中实现ESP32蓝牙配网的实战经验,重点解析了blufi协议的应用与优化。内容涵盖从开发环境配置、协议帧格式解析,到小程序端蓝牙通信、数据转换的核心步骤,并提供了配网状态机设计、错误处理及性能调优等进阶方案,旨在帮助开发者高效、稳定地完成物联网设备配网功能开发。

weixin_29159613的博客 460

MyBatis的三种分页方式实战详解

分页查询不仅可以减轻服务端的压力,提升查询速度和效率,还能减轻前端渲染的压力。需要注意的是,由于Java允许的最大整数为2147483647,因此LIMIT能使用的最大整数也是2147483647。一次性取出大量数据可能引起内存溢出,所以在大数据查询场合需要慎重使用。

m0_37643701的博客 2616

A2B音频总线在智能座舱中的应用

车载A2B链路音频是智能座舱的核心功能,涵盖车载音响、语音识别、e-Call、消噪及回声消除等应用,随着汽车智能网联化的发展,对音频的开发要求也越来越高,需要加入更先进、功能丰富的信息娱乐功能以满足消费者的用户体验。但传统的模拟并行音频信号传输方式,难以在功能增加与整车轻量化(线缆的重量及成本减少)之间取得均衡。这时候就需要A2B音频总线了。A2B音频总线用于连接车辆中的音频设备,如麦克风(MIC)、功放(AMP)、多媒体主机(Head Unit)和T-BOX等。通过一条低成本的非屏蔽双绞线UTP,进行跨距

怿星科技的博客 3937

mybatis实现分页的几种方式

本文目录借助数组进行分页借助Sql语句进行分页拦截器分页RowBounds实现分页 借助数组进行分页 原理:进行数据库查询操作时,获取到数据库中所有满足条件的记录,保存在应用的临时数组中,再通过List的subList方法,获取到满足条件的所有记录。 实现: 首先在dao层,创建StudentMapper接口,用于对数据库的操作。在接口中定义通过数组分页的查询方法,如下所示: List<Student> queryStudentsByArray(); 方法很简单,就是获取所有的数据,通过li

加油,努力,认真 4万+

LTspice 导入 PSpice 模型实战指南 --(解决语法兼容性与模型优化问题)

本文提供了将PSpice模型成功导入LTspice的详细实战指南。针对两者间的语法兼容性问题,文章以TI UCC23513为例,逐步讲解模型获取、符号创建、常见语法错误修改及仿真验证方法,并分享了模型优化与个人库管理技巧,帮助用户高效解决模型导入与仿真难题。

weixin_28278377的博客 824

【Claude】权限被拒绝 (Permission Denied) 全场景排查 — 已解决

权限配置是 Claude Code 安全使用的核心机制。通过合理的 allow/deny 规则、正确的通配符使用、子代理独立配置、定期安全审计,可以在保证安全性的同时不影响开发效率。deny 优先:deny 规则优先级高于 allow,先保护敏感资源通配符精确单层匹配,**递归匹配,Bash(cmd*)允许带参数最小权限:只允许必要的操作,避免Bash(*)等危险规则CI 用 skip:Headless 模式用避免挂起子代理独立:每个子代理单独配置权限,不自动继承保护密钥:deny.env。

一键难忘的博客 3950

Mybatis实现分页功能

分页可分为逻辑分页和物理分页。

weixin_51262054的博客 1万+

基于Simulink的强化学习(DQN)自主调节占空比

摘要:本文介绍了一种基于Simulink的强化学习(DQN)方法,用于Buck变换器的自主占空比调节。通过建立马尔可夫决策过程模型,设计了包含状态、动作和奖励函数的强化学习框架,并在Simulink中实现了Buck主电路、RL接口模块和DQN智能体的集成。实验表明,相比传统PID控制,DQN方法在负载突变和输入跌落等复合扰动下表现出更好的鲁棒性,电压超调小于1%,恢复时间缩短至0.3ms。文章还详细讨论了关键设计技巧、工程挑战及对策,并提出了多目标优化、先进算法应用等扩展方向,为智能电源控制提供了新思路。

amy_mhd的博客 76

MyBatis如何实现分页

如果你使用的数据库不支持特定的分页语法,或者想要更多灵活性,你可以通过自定义 SQL 实现分页逻辑。通常,你需要通过 RowBounds 或 PageHelper 来实现分页。

刘皇叔说Java的博客 9064

【并发编程五】c++进程通信——共享内存(shared memmory)

现代操作系统,对于内存管理,采⽤的是虚拟内存技术,也就是每个进程都有⾃⼰独⽴的虚拟内存空间,不同进程的虚拟内存映射到不同的物理内存中。所以,即使进程 A中 和 进程 B中 的虚拟地址是⼀样的,其实访问的是不同的物理内存地址,对于数据的增删查改互不影响。这样这个进程写⼊的东⻄,另外⼀个进程⻢上就能看到了,都不需要拷⻉来拷⻉去,传来传去,⼤⼤提⾼了进程间通信的速度。⽤了共享内存通信⽅式,带来新的问题,那就是如果多个进程同时修改同⼀个共享内存,很有可能就冲突了。那共享内存的⽅式,就很好的解决了这⼀问题。

junxuezheng的博客 1万+

皮肤病识别 - 使用DenseNet或EfficientNet模型在ISIC数据集上进行皮肤病识别任务

在本篇博客中,我们探讨了如何使用 DenseNet 和 EfficientNet 模型在 ISIC 数据集上进行皮肤病识别任务。我们加载了数据集,并进行了预处理。然后我们使用 Keras 构建了两个不同的模型,并训练和评估了它们。最后,我们使用训练好的模型对新的皮肤病图像进行了预测。

斌擎科技 1308

几种常见mybatis分页实现

mybatis框架分页实现,有几种方式,最简单的就是利用原生的sql关键字limit来实现,还有一种就是利用interceptor来拼接sql,实现和limit一样的功能,再一个就是利用PageHelper来实现。这里讲解这三种常见的实现方式: 无论哪种实现方式,我们返回的结果,不能再使用List了,需要一个自定义对象Pager。 package com.xxx.mybatis.bean; ...

feinifi的博客 13万+

Xilinx/AMD公司7系列FPGA的ISERDESE2仿真的”天坑”(附verilog的源码vivado仿真工程)

研究LVDS输出接口的ADC与7系列(ZYNQ)FPGA对接过程中,在Vivado中搭建了ISERDESE2的仿真工程,仿真结果ISERDESE2的并行输出口一直输出X或Z,这个坑之大,耗费了我数天的时间,可以称为“天坑”了。同步复位的要求肯定是高于异步复位的,古话说得好“两害相权取其轻”,所以,跟古话对着干就对了!就当RST是同步复位吧,最后经过反复验证,发现。开始怀疑复位信号是否高电平持续时间不够长?但是没有查到复位时间的要求 : - (

FPGA艺术家的博客 171

SpringBoot整合MyBatis四种常用的分页方式

扩展:PageHelper.startPage(int PageNum,int PageSize):用来设置页面的位置和展示的数据条目数,我们设置每页展示5条数据。PageInfo用来封装页面信息,返回给前台界面。PageInfo中的一些我们需要用到的参数如下表:

目前专注区块链相关技术的学习与分享 3718

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

重学SpringBoot3-MyBatis的三种分页方式

MyBatis 是一个流行的持久层框架,它支持定制 SQL、存储过程以及高级映射。MyBatis 避免了几乎所有的 JDBC 代码和手动设置参数以及获取结果集。分页是 Web 开发中常见的需求,尤其是处理大量数据时,合理的分页可以提高查询效率和用户体验。接下来,将介绍3种常用的 MyBatis 分页方式。

CoderJia的学习之路 1929

jre9下载 jdk9

(Java SE Runtime Environment 9.0) 9.0u175 官方最新版 【x86|x64】

【Mybatis】MyBatis分页的三种实现方式,Log4j的使用

本文介绍了MyBatis中实现分页查询的几种方式,重点讲解了日志工具Log4j的配置使用以及三种分页实现方法;一是通过SQL的LIMIT关键字实现,包括参数计算和Mapper接口设计;二是使用RowBounds实现,指出其在性能、灵活性等方面的缺陷,强调建立高效稳定的数据库访问层才是持久层交互的关键考虑因素。三是使用PageHelper,相关依赖以及Spring的配置说明,最终的实现效果和BootStarp的联合使用。

杨DaB的博客 1274

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

MyBatis 的三种分页方式你学废了嘛?

这份面试题几乎包含了他在一年内遇到的所有面试题以及答案,甚至包括面试中的细节对话以及语录,可谓是细节到极致,甚至简历优化和怎么投简历更容易得到面试机会也包括在内!也包括教你怎么去获得一些大厂,比如阿里,腾讯的内推名额!某位名人说过成功是靠99%的汗水和1%的机遇得到的,而你想获得那1%的机遇你首先就得付出99%的汗水!你只有朝着你的目标一步一步坚持不懈的走下去你才能有机会获得成功!成功只会留给那些有准备的人!” />

2301_79055240的博客 1101

mybatis-plus分页查询三种方法

mybatis-plus分页查询两种方法

李长渊的博客 6万+

MyBatis的三种分页方式

RowBounds 是 MyBatis提供的 (MyBatis自带的)用于分页的一个简单工具,它通过 Java 代码的方式来实现分页功能。使用 RowBounds 时,只需要在 Mapper 的方法中添加 RowBounds 参数即可。它通过改写原 SQL 语句,在 SQL 执行层面实现分页,它能够实现真正意义上的物理分页,从而大大提高了分页的效率。RowBounds 简单易用,但并不是一种高效的分页方式,因为它是通过在数据库返回全部结果之后,在内存中进行分页处理,这在处理大量数据时会非常低效。

我的博客 1147

springboot+mybatis实现数据分页(三种方式)

项目准备 1.创建用户表 2.使用spring初始化向导快速创建项目,勾选mybatis,web,jdbc,driver 添加lombok插件 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="

Kevinnsm的博客 1万+

Mybatis的四种分页方式详解

先自我介绍一下,小编13年上师交大毕业,曾经在小公司待过,去过华为OPPO等大厂,18年进入阿里,直到现在。因此我收集了一份《java开发全套学习资料》送给大家,初衷也很简单,就是希望帮助到想自学又不知道该从何学起的朋友,同时减轻大家的负担。使用方式https//github.com/pagehelper/Mybatis-PageHelper/blob/master/wikis/zh/HowToUse.md。PageHelper是一个第三方实现的分页拦截器插件,使用起来灵活且方便。拦截更改后的sql。...

web13618542420的博客 2万+

Mybatis的几种分页方式(数组分页、limit分页)

一、数组分页 原理:进行数据库查询操作时,获取到数据库中满足条件的记录,保存在对应的List集合中,通过List.subList方法,截取到满足条件的所有记录。 实现: 首先是dao层,创建UserMapper接口,用于对数据库的操作。在接口中定义查询数据的方法,如下: List&lt;User&gt; queryUsers(); 创建UserMapper.xml,编写查询的SQL语句...

对生活多一点乐趣 7111

Mybatis实现分页的三种方式

文章目录1、Limit实现分页2、RowBounds分页(不建议使用)3、MyBatis分页插件PageHelper(了解即可) 1、Limit实现分页 sql语句 SELECT * from user limit startIndex,pageSize 简单示例: user表 查询一:从第一行数据【 startIndex:0】开始,查询两行【pageSize:2】数据 SELECT * from user limit 0,2; 查询二:从第三行数据【 startIndex:2】

qq_45974648的博客 7642
上一篇: 任务调度框架 Quartz 用法指南(超详细)
下一篇: 为什么用了大牌工具后报表开发依然头痛
Java思维导图
博客等级 码龄10年 306粉丝 71原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值