• vue3+emelenui实现前端分页功能—最简单


    在一些后台管理系统或者博客管理系统中分页功能是很常见的一种服务,因为总不可能把很多数据放在一块,那样阅读起来很麻烦,所以需要分页。也是前后端中最为常见的一个功能

     先看一下分页场景的模拟。

     首先我们要去后端写点数据通过接口给前端:

    1. //控制类:
    2. package com.example.vue3spring.controller;
    3. import com.example.vue3spring.entity.Cell;
    4. import com.example.vue3spring.mapper.celllist;
    5. import org.springframework.beans.factory.annotation.Autowired;
    6. import org.springframework.web.bind.annotation.*;
    7. import java.util.List;
    8. @RestController
    9. public class Celllists {
    10. @Autowired
    11. private celllist cells;
    12. @RequestMapping(value = "/celllist",method = RequestMethod.GET)
    13. @CrossOrigin
    14. public List cel(){
    15. List cell1 = cells.cell();
    16. return cell1;
    17. }
    18. }
    1. //实体类
    2. package com.example.vue3spring.entity;
    3. public class Cell {
    4. private int id;
    5. private String number;
    6. private String name;
    7. private String address;
    8. private String area;
    9. private int loudong;
    10. private int households;
    11. private int affores;
    12. private String developers;
    13. private String property;
    14. private String creationtime;
    15. private String state;
    16. @Override
    17. public String toString() {
    18. return "Cell{" +
    19. "id=" + id +
    20. ", number='" + number + '\'' +
    21. ", name='" + name + '\'' +
    22. ", address='" + address + '\'' +
    23. ", area='" + area + '\'' +
    24. ", loudong=" + loudong +
    25. ", households=" + households +
    26. ", affores=" + affores +
    27. ", developers='" + developers + '\'' +
    28. ", property='" + property + '\'' +
    29. ", creationtime='" + creationtime + '\'' +
    30. ", state='" + state + '\'' +
    31. '}';
    32. }
    33. public int getId() {
    34. return id;
    35. }
    36. public void setId(int id) {
    37. this.id = id;
    38. }
    39. public String getNumber() {
    40. return number;
    41. }
    42. public void setNumber(String number) {
    43. this.number = number;
    44. }
    45. public String getName() {
    46. return name;
    47. }
    48. public void setName(String name) {
    49. this.name = name;
    50. }
    51. public String getAddress() {
    52. return address;
    53. }
    54. public void setAddress(String address) {
    55. this.address = address;
    56. }
    57. public String getArea() {
    58. return area;
    59. }
    60. public void setArea(String area) {
    61. this.area = area;
    62. }
    63. public int getLoudong() {
    64. return loudong;
    65. }
    66. public void setLoudong(int loudong) {
    67. this.loudong = loudong;
    68. }
    69. public int getHouseholds() {
    70. return households;
    71. }
    72. public void setHouseholds(int households) {
    73. this.households = households;
    74. }
    75. public int getAffores() {
    76. return affores;
    77. }
    78. public void setAffores(int affores) {
    79. this.affores = affores;
    80. }
    81. public String getDevelopers() {
    82. return developers;
    83. }
    84. public void setDevelopers(String developers) {
    85. this.developers = developers;
    86. }
    87. public String getProperty() {
    88. return property;
    89. }
    90. public void setProperty(String property) {
    91. this.property = property;
    92. }
    93. public String getCreationtime() {
    94. return creationtime;
    95. }
    96. public void setCreationtime(String creationtime) {
    97. this.creationtime = creationtime;
    98. }
    99. public String getState() {
    100. return state;
    101. }
    102. public void setState(String state) {
    103. this.state = state;
    104. }
    105. }
    1. //映射数据库关系
    2. package com.example.vue3spring.mapper;
    3. import com.example.vue3spring.entity.Cell;
    4. import org.apache.ibatis.annotations.Mapper;
    5. import org.apache.ibatis.annotations.Select;
    6. import org.springframework.stereotype.Repository;
    7. import java.util.List;
    8. @Mapper
    9. @Repository
    10. public interface celllist {
    11. @Select("select * from Celllist")
    12. public List cell();
    13. }

    连接数据库

    1. spring.datasource.type=com.alibaba.druid.pool.DruidDataSource
    2. spring.datasource.driver-class-name=com.mysql.jdbc.Driver
    3. spring.datasource.url=jdbc:mysql://localhost:3306/springboot?useSSL=false
    4. spring.datasource.username=root
    5. spring.datasource.password=w123456789
    6. mybatis-plus.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl

    pom文件依赖:

    1. dependency>
    2. <dependency>
    3. <groupId>com.baomidougroupId>
    4. <artifactId>mybatis-plus-boot-starterartifactId>
    5. <version>3.4.2version>
    6. dependency>
    7. <dependency>
    8. <groupId>mysqlgroupId>
    9. <artifactId>mysql-connector-javaartifactId>
    10. <version>8.0.23version>
    11. dependency>
    12. <dependency>
    13. <groupId>com.alibabagroupId>
    14. <artifactId>druid-spring-boot-starterartifactId>
    15. <version>1.1.23version>
    16. dependency>

    SQl文件;

    1. /*
    2. Navicat MySQL Data Transfer
    3. Source Server : springbootSQL
    4. Source Server Version : 80030
    5. Source Host : localhost:3306
    6. Source Database : springboot
    7. Target Server Type : MYSQL
    8. Target Server Version : 80030
    9. File Encoding : 65001
    10. Date: 2023-09-10 14:14:00
    11. */
    12. SET FOREIGN_KEY_CHECKS=0;
    13. -- ----------------------------
    14. -- Table structure for celllist
    15. -- ----------------------------
    16. DROP TABLE IF EXISTS `celllist`;
    17. CREATE TABLE `celllist` (
    18. `id` int NOT NULL AUTO_INCREMENT,
    19. `number` varchar(55) DEFAULT NULL,
    20. `name` varchar(255) DEFAULT NULL,
    21. `address` varchar(255) DEFAULT NULL,
    22. `area` varchar(255) DEFAULT NULL COMMENT '面积\r\n',
    23. `loudong` int DEFAULT NULL,
    24. `households` int DEFAULT NULL,
    25. `afforest` int DEFAULT NULL,
    26. `developers` varchar(255) DEFAULT NULL,
    27. `property` varchar(255) DEFAULT NULL,
    28. `creationtime` varchar(255) DEFAULT NULL,
    29. `state` varchar(255) DEFAULT NULL,
    30. PRIMARY KEY (`id`)
    31. ) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
    32. -- ----------------------------
    33. -- Records of celllist
    34. -- ----------------------------
    35. INSERT INTO `celllist` VALUES ('1', 'z_40586661', '金域华府', '合肥市蜀山区', '12000', '25', '160', '45', '万科', '万科物业', '2023-09-10 09:50:54.000000', '正常');
    36. INSERT INTO `celllist` VALUES ('2', 'z_40586660', '金域华府', '合肥市撒的去', '1145', '21', '145', '39', '徐汇', '永生物业', '2023-09-09 09:52:14.000000', '正常');
    37. INSERT INTO `celllist` VALUES ('3', 'z_40586662', '万福国际', '湖北省武汉市', '1658', '36', '256', '60', '天湖', '天湖物业', '2023-08-29 09:53:19.000000', '正常');
    38. INSERT INTO `celllist` VALUES ('4', 'z_40586663', '暨南国际', '湖北省北京市', '568', '145', '485', '30', '背景', '背景物业', '2023-09-12 09:54:17.000000', '正常');

    前端vue+elementui部分:

    1. <template>
    2. <div style="width: 100% ;margin:0px 10px">
    3. <el-input class="search" v-model="search" placeholder="Please input" />
    4. <el-button type="primary">查询el-button>
    5. <div style="margin:15px">
    6. <el-button type="warning" :icon="Delete">批量删除el-button>
    7. <el-button type="primary" :icon="CirclePlus">添加el-button>
    8. div>
    9. <el-table :data="tableData.slice((page-1)*limt,page*limt)" style="width: 100%;">
    10. <el-table-column prop="id" type="selection" width="55" />
    11. <el-table-column prop="id" label="ID" width="55" />
    12. <el-table-column prop="number" label="小区编号" width="55" />
    13. <el-table-column prop="name" label="小区名称" />
    14. <el-table-column prop="address" label="坐落地址" />
    15. <el-table-column prop="area" label="占地面积(m2)" />
    16. <el-table-column prop="loudong" label="总栋数" />
    17. <el-table-column prop="households" label="总户数" />
    18. <el-table-column prop="affores" label="绿化率" />
    19. <el-table-column prop="developers" label="开发商名称" />
    20. <el-table-column prop="property" label="物业公司名称" />
    21. <el-table-column prop="creationtime" label="创建时间" />
    22. <el-table-column prop="state" label="状态" />
    23. <el-table-column prop="address" label="操作" />
    24. el-table>
    25. <el-pagination
    26. background
    27. layout="total, sizes, prev, pager, next, jumper"
    28. :page-size="limt"
    29. style="margin-top:2%"
    30. :page-sizes="[10, 20, 30, 40]"
    31. :current-page="page"
    32. :total="totl"
    33. @size-change="handleSizeChange"
    34. @current-change="handleCurrentChange"
    35. />
    36. div>
    37. template>
    38. <script setup>
    39. import { CirclePlus,Delete } from '@element-plus/icons-vue'
    40. import {ref} from 'vue'
    41. import axios from 'axios';
    42. const search = ref("");
    43. const tableData = ref([]);
    44. const page = ref(1);
    45. const limt = ref(1);
    46. const totl = ref(0);
    47. axios({
    48. url:"http://localhost:8080/celllist",
    49. method:"get"
    50. }).then(res=>{
    51. console.log(res.data);
    52. tableData.value=res.data;
    53. console.log(tableData.value);
    54. totl.value=res.data.length
    55. })
    56. function handleSizeChange(val){
    57. console.log(val);
    58. limt.value=val;
    59. }
    60. function handleCurrentChange(val){
    61. console.log(val);
    62. page.value=val
    63. }
    64. script>
    65. <style scoped>
    66. .search{
    67. margin: 50px 10px 50px 50px;
    68. width: 25%;
    69. }
    70. style>

    若有不懂地方,推荐视频:https://www.bilibili.com/video/BV1Q3411u7cF/?p=2&spm_id_from=pageDriver&vd_source=0621c8112dd04675d7876e772210635b

  • 相关阅读:
    windows查找指定端口程序,终止程序
    编程语言除了面向过程和面向对象还有什么
    2022最新版-李宏毅机器学习深度学习课程-P26 自注意力机制
    嵌入式C语言中整形溢出问题分析
    23种设计模式之命令模式(Command Pattern)
    springcloud搭建 初级人员的使用搭建。sentinel使用官网有详细的使用方法
    训练营第二十七天 | 491.递增子序列46.全排列47.全排列 II332.重新安排行程51. N皇后
    vue+导出excel报表
    Web攻防01-ASP应用相关漏洞-HTTP.SYS&IIS短文件&文件解析&ACCESS注入
    C++vector的简单模拟实现
  • 原文地址:https://blog.csdn.net/qq_63656102/article/details/132790681