{"id":16555,"date":"2024-03-15T13:12:23","date_gmt":"2024-03-15T13:12:23","guid":{"rendered":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/"},"modified":"2025-08-07T03:56:40","modified_gmt":"2025-08-07T03:56:40","slug":"how-to-use-pagehelper-to-query-all-data","status":"publish","type":"post","link":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/","title":{"rendered":"How to use pagehelper to query all data"},"content":{"rendered":"<p>To query all data using the PageHelper plugin, follow the steps below:<\/p>\n<ol>\n<li>Add the dependency of PageHelper in the pom.xml file of the project.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>com.github.pagehelper<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">groupId<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>pagehelper<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">artifactId<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">version<\/span>&gt;<\/span>\u6700\u65b0\u7248\u672c\u53f7<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">version<\/span>&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">dependency<\/span>&gt;<\/span>\r\n<\/code><\/pre>\n<ol>\n<li>In the configuration file of MyBatis (usually mybatis-config.xml), add the PageHelper plugin configuration.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">plugins<\/span>&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">plugin<\/span> <span class=\"hljs-attr\">interceptor<\/span>=<span class=\"hljs-string\">\"com.github.pagehelper.PageInterceptor\"<\/span>&gt;<\/span>\r\n        <span class=\"hljs-comment\">&lt;!-- \u8bbe\u7f6e\u6570\u636e\u5e93\u7c7b\u578b --&gt;<\/span>\r\n        <span class=\"hljs-tag\">&lt;<span class=\"hljs-name\">property<\/span> <span class=\"hljs-attr\">name<\/span>=<span class=\"hljs-string\">\"dialect\"<\/span> <span class=\"hljs-attr\">value<\/span>=<span class=\"hljs-string\">\"\u6570\u636e\u5e93\u65b9\u8a00\"<\/span>\/&gt;<\/span>\r\n    <span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">plugin<\/span>&gt;<\/span>\r\n<span class=\"hljs-tag\">&lt;\/<span class=\"hljs-name\">plugins<\/span>&gt;<\/span>\r\n<\/code><\/pre>\n<ol>\n<li>In Java code, use the PageHelper.startPage method to initiate a pagination query, and then call the method to retrieve all data.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-keyword\">import<\/span> com.github.pagehelper.PageHelper;\r\n<span class=\"hljs-keyword\">import<\/span> com.github.pagehelper.PageInfo;\r\n\r\n<span class=\"hljs-comment\">\/\/ \u5f00\u542f\u5206\u9875\u67e5\u8be2\uff0c\u8bbe\u7f6e\u9875\u7801\u548c\u6bcf\u9875\u6570\u636e\u91cf<\/span>\r\nPageHelper.startPage(pageNum, pageSize);\r\n<span class=\"hljs-comment\">\/\/ \u67e5\u8be2\u5168\u90e8\u6570\u636e<\/span>\r\nList&lt;YourEntity&gt; dataList = yourMapper.selectAll();\r\n<span class=\"hljs-comment\">\/\/ \u4f7f\u7528PageInfo\u5bf9\u7ed3\u679c\u8fdb\u884c\u5305\u88c5<\/span>\r\nPageInfo&lt;YourEntity&gt; pageInfo = <span class=\"hljs-keyword\">new<\/span> <span class=\"hljs-title class_\">PageInfo<\/span>&lt;&gt;(dataList);\r\n<\/code><\/pre>\n<p>In the code above, pageNum represents the page number to be queried and pageSize represents the amount of data to be displayed per page. YourMapper is a MyBatis Mapper interface that you have defined yourself, with the selectAll method being a method defined in this Mapper interface for querying all data.<\/p>\n<ol>\n<li>Finally, use the PageInfo object as needed to obtain pagination information and query results.<\/li>\n<\/ol>\n<pre class=\"post-pre\"><code><span class=\"hljs-comment\">\/\/ \u83b7\u53d6\u603b\u8bb0\u5f55\u6570<\/span>\r\n<span class=\"hljs-type\">long<\/span> <span class=\"hljs-variable\">total<\/span> <span class=\"hljs-operator\">=<\/span> pageInfo.getTotal();\r\n<span class=\"hljs-comment\">\/\/ \u83b7\u53d6\u5f53\u524d\u9875\u7684\u6570\u636e<\/span>\r\nList&lt;YourEntity&gt; currentPageData = pageInfo.getList();\r\n\r\n<span class=\"hljs-comment\">\/\/ \u53ef\u4ee5\u6839\u636e\u9700\u8981\u6253\u5370\u5206\u9875\u4fe1\u606f<\/span>\r\nSystem.out.println(<span class=\"hljs-string\">\"\u603b\u8bb0\u5f55\u6570\uff1a\"<\/span> + total);\r\nSystem.out.println(<span class=\"hljs-string\">\"\u5f53\u524d\u9875\u7801\uff1a\"<\/span> + pageInfo.getPageNum());\r\nSystem.out.println(<span class=\"hljs-string\">\"\u6bcf\u9875\u6570\u636e\u91cf\uff1a\"<\/span> + pageInfo.getPageSize());\r\nSystem.out.println(<span class=\"hljs-string\">\"\u603b\u9875\u6570\uff1a\"<\/span> + pageInfo.getPages());\r\n<\/code><\/pre>\n<p>The steps above outline how to use the PageHelper plugin to query all data. Remember to configure and call it according to your own needs.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>To query all data using the PageHelper plugin, follow the steps below: Add the dependency of PageHelper in the pom.xml file of the project. &lt;dependency&gt; &lt;groupId&gt;com.github.pagehelper&lt;\/groupId&gt; &lt;artifactId&gt;pagehelper&lt;\/artifactId&gt; &lt;version&gt;\u6700\u65b0\u7248\u672c\u53f7&lt;\/version&gt; &lt;\/dependency&gt; In the configuration file of MyBatis (usually mybatis-config.xml), add the PageHelper plugin configuration. &lt;plugins&gt; &lt;plugin interceptor=&#8221;com.github.pagehelper.PageInterceptor&#8221;&gt; &lt;!&#8211; \u8bbe\u7f6e\u6570\u636e\u5e93\u7c7b\u578b &#8211;&gt; &lt;property name=&#8221;dialect&#8221; value=&#8221;\u6570\u636e\u5e93\u65b9\u8a00&#8221;\/&gt; &lt;\/plugin&gt; &lt;\/plugins&gt; In Java [&hellip;]<\/p>\n","protected":false},"author":13,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_import_markdown_pro_load_document_selector":0,"_import_markdown_pro_submit_text_textarea":"","footnotes":""},"categories":[1],"tags":[453,1402,299,1404,1403],"class_list":["post-16555","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-development","tag-guide","tag-programming","tag-technology","tag-tutorial"],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v21.5 (Yoast SEO v21.5) - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to use pagehelper to query all data - Blog - Silicon Cloud<\/title>\n<meta name=\"description\" content=\"Learn about how to use pagehelper to query all data. Comprehensive guide with examples and best practices.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to use pagehelper to query all data\" \/>\n<meta property=\"og:description\" content=\"Learn about how to use pagehelper to query all data. Comprehensive guide with examples and best practices.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\" \/>\n<meta property=\"og:site_name\" content=\"Blog - Silicon Cloud\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\" \/>\n<meta property=\"article:published_time\" content=\"2024-03-15T13:12:23+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-07T03:56:40+00:00\" \/>\n<meta name=\"author\" content=\"Isabella Edwards\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:site\" content=\"@SiliCloudGlobal\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Isabella Edwards\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\"},\"author\":{\"name\":\"Isabella Edwards\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\"},\"headline\":\"How to use pagehelper to query all data\",\"datePublished\":\"2024-03-15T13:12:23+00:00\",\"dateModified\":\"2025-08-07T03:56:40+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\"},\"wordCount\":159,\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"keywords\":[\"Development\",\"guide\",\"programming\",\"technology\",\"tutorial\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\",\"name\":\"How to use pagehelper to query all data - Blog - Silicon Cloud\",\"isPartOf\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\"},\"datePublished\":\"2024-03-15T13:12:23+00:00\",\"dateModified\":\"2025-08-07T03:56:40+00:00\",\"description\":\"Learn about how to use pagehelper to query all data. Comprehensive guide with examples and best practices.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.silicloud.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to use pagehelper to query all data\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#website\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"name\":\"Silicon Cloud Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#organization\",\"name\":\"Silicon Cloud Blog\",\"url\":\"https:\/\/www.silicloud.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"contentUrl\":\"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png\",\"width\":1024,\"height\":1024,\"caption\":\"Silicon Cloud Blog\"},\"image\":{\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/SiliCloudGlobal\/\",\"https:\/\/twitter.com\/SiliCloudGlobal\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd\",\"name\":\"Isabella Edwards\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g\",\"caption\":\"Isabella Edwards\"},\"url\":\"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"How to use pagehelper to query all data - Blog - Silicon Cloud","description":"Learn about how to use pagehelper to query all data. Comprehensive guide with examples and best practices.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/","og_locale":"en_US","og_type":"article","og_title":"How to use pagehelper to query all data","og_description":"Learn about how to use pagehelper to query all data. Comprehensive guide with examples and best practices.","og_url":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/","og_site_name":"Blog - Silicon Cloud","article_publisher":"https:\/\/www.facebook.com\/SiliCloudGlobal\/","article_published_time":"2024-03-15T13:12:23+00:00","article_modified_time":"2025-08-07T03:56:40+00:00","author":"Isabella Edwards","twitter_card":"summary_large_image","twitter_creator":"@SiliCloudGlobal","twitter_site":"@SiliCloudGlobal","twitter_misc":{"Written by":"Isabella Edwards","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/#article","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/"},"author":{"name":"Isabella Edwards","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd"},"headline":"How to use pagehelper to query all data","datePublished":"2024-03-15T13:12:23+00:00","dateModified":"2025-08-07T03:56:40+00:00","mainEntityOfPage":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/"},"wordCount":159,"publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"keywords":["Development","guide","programming","technology","tutorial"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/","url":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/","name":"How to use pagehelper to query all data - Blog - Silicon Cloud","isPartOf":{"@id":"https:\/\/www.silicloud.com\/blog\/#website"},"datePublished":"2024-03-15T13:12:23+00:00","dateModified":"2025-08-07T03:56:40+00:00","description":"Learn about how to use pagehelper to query all data. Comprehensive guide with examples and best practices.","breadcrumb":{"@id":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.silicloud.com\/blog\/how-to-use-pagehelper-to-query-all-data\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.silicloud.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to use pagehelper to query all data"}]},{"@type":"WebSite","@id":"https:\/\/www.silicloud.com\/blog\/#website","url":"https:\/\/www.silicloud.com\/blog\/","name":"Silicon Cloud Blog","description":"","publisher":{"@id":"https:\/\/www.silicloud.com\/blog\/#organization"},"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.silicloud.com\/blog\/#organization","name":"Silicon Cloud Blog","url":"https:\/\/www.silicloud.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","contentUrl":"https:\/\/www.silicloud.com\/blog\/wp-content\/uploads\/2023\/11\/EN-SILICON-Full.png","width":1024,"height":1024,"caption":"Silicon Cloud Blog"},"image":{"@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/SiliCloudGlobal\/","https:\/\/twitter.com\/SiliCloudGlobal"]},{"@type":"Person","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/5579144e23c225c8188167f3e3f888dd","name":"Isabella Edwards","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.silicloud.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/d4d4dec47f553ac7961d9fa4cc9bdcdcf5b7ce5106594330b6d25c5694fdbaec?s=96&d=mm&r=g","caption":"Isabella Edwards"},"url":"https:\/\/www.silicloud.com\/blog\/author\/isabellaedwards\/"}]}},"_links":{"self":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/16555","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/comments?post=16555"}],"version-history":[{"count":1,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/16555\/revisions"}],"predecessor-version":[{"id":50109,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/posts\/16555\/revisions\/50109"}],"wp:attachment":[{"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/media?parent=16555"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/categories?post=16555"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.silicloud.com\/blog\/wp-json\/wp\/v2\/tags?post=16555"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}