SpringBoot整合Mybatis分页插件PageHelper

Springboot整合myBatis(附加pagehelper分页插件) Spring boot整合myBatis(附加pagehelper分页插件)前提第一步,创建spring boot,导入maven依赖第二步,进行appliction配置第三步,将springboot启动类进行扫描接口配置第四步创建三层架构项目第四步,运行项目,访问Controller接口分页插件pagehelper总结 前提 大家好,我在身边的人当着发现对spring boot整合mybatis... 阅读详情

引入pom.xml坐标

        <dependency>
            <groupId>com.github.pagehelper</groupId>
            <artifactId>pagehelper-spring-boot-starter</artifactId>
            <version>1.2.5</version>
        </dependency>

配置文件添加

#pageHelper配置
pagehelper:
 helperDialect: mysql
 reasonable: true
 supportMethodsArguments: true
 params: count=countSql

mapper.xml中SQL语句

<select id="queryPage"   resultMap="BaseResponse">
      SELECT 
    	id,
    	user_id,
    	table_num,
    	order_num,
    	order_price,
    	is_deleted,
    	is_payed,
    	create_time,
    	pay_time,
    	pay_type
      FROM goods_order
      where 1=1
        <include refid="pubItem"/>
      ORDER BY create_time DESC
    </select>


    <sql id="pubItem">
         <if test="user_id != null and user_id !='' ">and user_id = #{user_id}</if>
         <if test="table_num != null and table_num !='' ">and table_num = #{table_num}</if>
         <if test="order_num != null and order_num !='' ">and order_num = #{order_num}</if>
         <if test="order_price != null and order_price !='' ">and order_price = #{order_price}</if>
         <if test="is_deleted != null and is_deleted !='' ">and is_deleted = #{is_deleted}</if>
         <if test="is_payed != null and is_payed !='' ">and is_payed = #{is_payed}</if>
         <if test="create_time != null and create_time !='' ">and create_time = #{create_time}</if>
         <if test="pay_time != null and pay_time !='' ">and pay_time = #{pay_time}</if>
         <if test="pay_type != null and pay_type !='' ">and pay_type = #{pay_type}</if>
    </sql>

DO(dao)层接口

dao层正常使用即可

Mybatis分页插件PageHelper代码

 

实体类:GoodsOrder封装数据模型。

BO层


public interface GoodsOrderBO {
    /**
     * <pre>
     * 分页查询用户订单
     * </pre>
     *
     * @param page  分页信息
     * @param goodsOrder 查询条件
     * @return 数据集合
     * @throws
     */
    PageInfo<GoodsOrder> queryPage(GoodsOrder goodsOrder, int pageNum, int pageSize);
   
}
@Service("GoodsOrderBO")
public class GoodsOrderBOImpl implements GoodsOrderBO {
    @Autowired
    private GoodsOrderDO goodsOrderDO;


    @Override
    public PageInfo<GoodsOrder> queryPage(GoodsOrder goodsOrder,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<GoodsOrder> resList = goodsOrderDO.queryPage(goodsOrder);
        PageInfo<GoodsOrder> page =  new PageInfo<>(resList);
        return page;
    }

   
}

AO层


public interface GoodsOrderAO {
    
    /**
     * <pre>
     * 分页查询 用户订单
     * </pre>
     *
     * @param page  分页信息
     * @param query 查询条件
     * @return      分页数据集合
     */
    Result<PageInfo<GoodsOrder>> queryPage(GoodsOrderQuery query, int pageNum, int pageSize);
  

}
package com.dinner.order.ao.impl;

import com.dinner.commons.domain.GoodsOrder;
import com.dinner.commons.page.PageResult;
import com.dinner.commons.query.GoodsOrderQuery;
import com.dinner.commons.request.GoodsOrderReq;
import com.dinner.commons.result.Result;
import com.dinner.commons.result.ResultCodeEnum;
import com.dinner.order.ao.GoodsOrderAO;
import com.dinner.order.bo.GoodsOrderBO;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service("GoodsOrderAO")
public class GoodsOrderAOImpl implements GoodsOrderAO {

    @Autowired
    private GoodsOrderBO goodsOrderBO;

 

    @Override
    public Result<PageInfo<GoodsOrder>> queryPage(GoodsOrderQuery query,int pageNum,int pageSize) {
        Result<PageInfo<GoodsOrder>> pr = new Result<>();
        try {
            GoodsOrder goodsOrder = new GoodsOrder();
            BeanUtils.copyProperties(query,goodsOrder);
            PageInfo<GoodsOrder> list = goodsOrderBO.queryPage(goodsOrder, pageNum, pageSize);
             pr = pr.success(list);
        } catch (Exception e) {
            pr =pr.error(ResultCodeEnum.FAIL.getCode(),e.getMessage());
        }
        return pr;
    }

}

Result为json数据处理类

测试结果

SpringBoot整合Mybatis-PageHelper分页插件实战指南 数据分页是Web应用开发中的基础功能,通过物理分页技术可以有效提升查询性能和用户体验。Mybatis-PageHelper作为Mybatis生态中的分页插件,基于拦截器机制实现SQL自动改写,支持多种数据库方言。在SpringBoot项目中,通过简单的starter配置即可快速集成,大幅减少传统分页开发的重复代码量。该插件不仅提供基础分页功能,还支持参数化分页、Lambda表达式等现代Java特性,并能通过异步count查询等优化手段处理大数据量场景。典型应用包括后台管理系统数据展示、报表导出分页处理等,是 阅读详情

相关推荐

queryPage.js

queryPage.js

QueryPage使用示例

1、通过关联的表的某字段

小强快跑~~ 1万+

【面试经验】大疆笔试-计算机视觉算法B卷

3、a=np.random.randn(3,3) b=np.random.randn(3,1) ,那么c=a*b的维度应该是:*是元素乘法或者torch.mul,@才是矩阵乘法或者torch.matmul,不会触发广播机制;8、将分辨率降低一半时,精标定内参(fx、fy、cx、cy、k1、k2、k3)焦距、光心、畸变系数将分别变成(fx、fy、cx/2、cy/2、k1、k2、k3),只能搜到光心变成一半,畸变系数不变。12、KLT算法在频闪光源、重复纹理、高速机动、环境照度低的情况下效果显著下降。

litterfinger的博客 1449

在分页表连接中实现搜索(即模糊查询)

先看下效果图 先讲解下思路:首先是在DAO层写根据姓名和班级进行模糊查询的方法,(sql:select * from cla c join stu s on s.cid = c.cid where s.name like ? and cname like ?)sql 语句语法可能不太对,但是大题意思是对的。根据两个条件进行查询,所以要用and。写完后端,前端的就是要注意vue的传参了,要把数据全...

生花脱颖的博客 1790

python等级考试——一级知识点汇总(不包含turtle画图)

本篇文章是针对中国电子学会青少年编程等级考试的,适合初学者以及青少年编程学习者

weixin_65350557的博客 9038

Delphi开发者必备:CEF4Delphi跨平台浏览器嵌入实战指南(含Lazarus适配)

本文详细介绍了Delphi开发者如何利用CEF4Delphi实现跨平台浏览器嵌入,包括环境配置、Lazarus适配、ARM架构优化及Firemonkey集成等实战技巧。通过Chromium引擎的强大功能,开发者可以轻松为传统桌面应用添加现代浏览器特性,提升多平台开发效率。

weixin_29233333的博客 230

实现分页功能

【代码】实现分页功能。

Z_zpXP的博客 258

详解大端模式和小端模式

详解大端模式和小端模式 一、大端模式和小端模式的起源         关于大端小端名词的由来,有一个有趣的故事,来自于Jonathan Swift的《格利佛游记》:Lilliput和Blefuscu这两个强国在过去的36个月中一直在苦战。战争的原因:大家都知道,吃鸡蛋的时候,原始的方法是打破鸡蛋较大的一端,可以那时的皇帝的祖父由于小时侯吃鸡蛋,按这种方法把手指弄破了,因此他的父亲,就下令,命令

ce123的技术博客 19万+

java数据分页几种方式

1.使用PageUtils Service: /** * 分页查询 * * @param params 查询条件 * @return PageUtils */ PageUtils queryPage(Map<String, Object> params); ServiceImpl: Page<数据库对象实...

weixin_41476211的博客 1433

1、 快速掌握R:初学者的计量经济学指南

本博文旨在为初学者提供一个快速掌握R语言的指南,特别是针对计量经济学领域的应用。内容涵盖了R的基本操作、数据管理、可视化、函数编写以及高级统计分析方法,如OLS回归、异方差修正和集群标准误差计算等。通过实际示例和详细说明,帮助读者在数据分析和科学研究中更加得心应手。

weixin_35734408的博客 151

YOLOv10涨点改进:SPPF原创自研创新 | SPPF创新结构,重新设计全局平均池化层和全局最大池化层,增强全局视角信息和不同尺度大小的特征

SPPF原创自研创新

①答疑群聊服务;②YOLO大模型知识问答系统;③计算机视觉论文生成智能体; 2088

分页查询之通用查询pageQuery的代码

分页查询之通用PageQuery

ABC_wangershao的博客 6876

复现论文《孤岛微电网环境下基于物理模型引导的深度强化学习VSG频率控制方法》

本文提出了一种结合物理模型与深度强化学习的孤岛微电网VSG频率控制方法。通过建立VSG小信号模型并设计可变系数控制器,将物理知识融入深度强化学习框架,解决了高维参数和机组耦合带来的控制难题。复现代码实现了三个核心组件:VSGSmallSignalModel建模VSG动态特性,VariableCoefficientController实现参数自适应调节,PhysicsGuidedDRL整合DQN算法与物理模型引导的奖励机制。该方法通过模型驱动与数据驱动的优势互补,提升了频率控制性能,其中物理模型既作为先验知识

huanghm88的专栏 127

springboot整合Mybatis和配置PageHelper分页插件

2.配置Mybatis   2.1 引入依赖      &lt;dependency&gt;      &lt;groupId&gt;org.mybatis.spring.boot&lt;/groupId&gt;      &lt;artifactId&gt;mybatis-spring-boot-starter&lt;/artifactId&gt;      &lt;version&gt;1....

qq_41915592的博客 869

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

深度学习工具包 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")

Springboot整合Mybatis的分页插件PageHelper

第一件事,导入jar包,贴上maven &lt;dependency&gt; &lt;groupId&gt;com.github.pagehelper&lt;/groupId&gt; &lt;artifactId&gt;pagehelper-spring-boot-starter&lt;/artifactId&gt; ...

beyond丿灬的博客 2574

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

springboot分页插件_Spring boot整合Mybatis Generator以及PageHelper源码分析

整合MBG为什么使用MBG使用过Mybatis的朋友应该都知道,在使用之前我们需要根据数据库表的情况在项目中创建出对应的实体类,sql语句接口层,XML文件等,这一系列的操作是非常简单的,但又是必不可少的,耗时耗力还没什么营养,如果数据库的表足够多的时候还要手动创建这些内容,那对程序员来说简直是一种折磨,所以在实际的开发过程中MBG是非常有必要的,下面我们就详细介绍如何在Spring boot项目...

weixin_39852491的博客 165

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

SpringBoot3整合MyBatis-Plus分页插件。SpringBoot3整合MyBatis+PageHelper分页插件。(SpringBoot3.3.10)

本篇博客核心内容:基于SpringBoot3实现整合MyBatis-Plus分页插件(数据层或业务层实现分页)。基于SpringBoot3实现整合MyBatis+PageHelper分页插件。其中测试与响应使用第三方工具Apifox进行模拟前端请求,,,

岁岁岁平安的博客 2675

【SpringBoot】SpringBoot整合MyBatis,以及配置PageHelper分页插件

SpringBoot整合MyBatis 首先创建一个SpringBoot工程 1、导入依赖 此处MySQL使用的版本是8.0.22,也是SpringBoot中默认版本 如果是MySQL5.7,则在依赖上手动指明版本<version>5.7</version> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artif

她的坏机器人 649

springboot整合mybatis之分页插件pagehelper

今天更新

weixin_44092924的博客 483

SpringBoot整合Mybatis使用分页插件PageHelper

SpringBoot整合Mybatis使用分页插件PageHelper很简单 1、引入依赖 <!-- 分页插件依赖 --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper</artifactId> ...

曹举的个人博客 646

springboot整合mybatis和分页插件pagehelper

最近使用mybatis比较少,也没有用过springboot整合过mybatis及其分页插件,在这个过程中出现了好多问题,开贴记录一下,希望大家能够避免入坑。 proterrties的配置,我这里没有贴出数据的配置 #mybatis mybatis.mapper-locations=classpath:com.wyb.mybaties.mybaties.mapper/*.xml #mybatis....

qq_38490173的博客 248

springboot整合mybatis分页插件PageHelper实战

https://www.cnblogs.com/xifengxiaoma/p/11027551.html

weixin_38568503的博客 5199

SpringBoot整合Mybatis使用通用Mapper和分页插件PageHelper

我的上一篇博客里面介绍了,如何在SpringBoot环境下集成Mybatis SpringBoot整合Mybatis 这篇主要来讲解一下SpringBoot整合Mybatyis使用通用Mapper和分页插件PageHelper 使用的SpringBoot版本2.1.4.RELEASE,Mysql版本8.0+ 添加依赖,都有注释 <!-- mysql驱动 --> ...

shijiujiu33的博客 1374

Spring Boot整合Mybatis+PageHelper分页插件

Spring Boot整合Mybatis+PageHelper分页插件 Pom.xml 基础的依赖我就不再这里给大家一个展示出来了,把用到的依赖给大家展示出来 <!-- Mybatis依赖 --> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactI...

sl010420的博客 188

spring boot整合mybatis+通用mapper+pagehelper分页插件

spring boot整合mybatis+通用mapper+pagehelper分页插件 pom依赖 <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0....

chouteng7995的博客 168
上一篇: 使用java反射机制与mybatis框架搭建DAO层,实现数据的传输,简化了实现类中每次写得到和关闭sqlSession,交给工具类来处理。
下一篇: Spring Cloud Feign调用服务提供者
java_zuiweng
博客等级 码龄9年 24粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值