PageHelper+BootStrap+Vue+axios实现分页功能

2023-11-18

PageHelper+BootStrap+Vue+axios实现分页功能

效果展示

在这里插入图片描述

技术栈

前端技术:Vue2.5.16+axios、BootStrap3.3.7
后端技术:SpringBoot2.7.9、MyBatisPlus3.5.1、MySQL8

后端开发

1.配置MyBatisPlus

1.1在pom.xml中添加依赖

		<!-- Spring&SpringMVC -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <!-- mybatis-plus -->
        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.1</version>
        </dependency>
        <!-- lombok -->
        <dependency>
            <groupId>org.projectlombok</groupId>
            <artifactId>lombok</artifactId>
            <version>1.18.20</version>
        </dependency>
        <!-- mysql-connector -->
        <dependency>
            <groupId>mysql</groupId>
            <artifactId>mysql-connector-java</artifactId>
            <version>8.0.32</version>
        </dependency>

1.2在application.yum中配置数据源

server:
  port: 8070
spring:
  datasource:
    type: com.zaxxer.hikari.HikariDataSource
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://127.0.01:3306/test_plus?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=false&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
    username: root
    password: Aa123123.
mybatis-plus:
  type-aliases-package: demo.entity
  configuration:
    log-impl: org.apache.ibatis.logging.stdout.StdOutImpl
  global-config:
    db-config:
      table-prefix: t_
      id-type: auto
  mapper-locations: classpath:mappers/*.xml

1.3在启动类中配置分页插件

package demo;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.MybatisPlusInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SpringBootApplication
@Configuration
@MapperScan("demo.mapper")
public class Demo {

    /** 配置分页插件*/
    @Bean
    public MybatisPlusInterceptor mybatisPlusInterceptor() {
        MybatisPlusInterceptor interceptor = new MybatisPlusInterceptor();
        interceptor.addInnerInterceptor(new PaginationInnerInterceptor(DbType.MYSQL));
        return interceptor;
    }

    public static void main(String[] args) {
        SpringApplication.run(Demo.class);
    }
}

1.4SQL脚本

SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;

-- ----------------------------
-- Table structure for t_article
-- ----------------------------
DROP TABLE IF EXISTS `t_article`;
CREATE TABLE `t_article` (
  `id` bigint(20) NOT NULL AUTO_INCREMENT,
  `title` varchar(50) DEFAULT NULL,
  `logo` varchar(255) DEFAULT NULL,
  `descn` varchar(160) DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  `cid` bigint(20) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=1630090627736408069 DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_article
-- ----------------------------
BEGIN;
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1, '扬子xx', NULL, 'eeeeeeee', '2023-01-02 00:00:00', 2);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090618022400001, '扬子晚报1', NULL, 'dddsfjslfjalskd', '2023-01-03 00:00:00', 2);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090625282740226, '扬子晚报2', NULL, 'dddsfjslfjalskd', '2023-01-04 00:00:00', 2);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090625865748482, '扬子晚报3', NULL, 'dddsfjslfjalskd', '2023-01-05 00:00:00', 1);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090626520059905, '扬子晚报4', NULL, 'dddsfjslfjalskd', '2023-01-06 00:00:00', 2);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090627165982721, '扬子晚报5', NULL, 'dddsfjslfjalskd', '2023-01-07 00:00:00', 1);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090627736408066, '扬子晚报6', NULL, 'dddsfjslfjalskd', '2023-01-08 00:00:00', 1);
INSERT INTO `t_article` (`id`, `title`, `logo`, `descn`, `create_time`, `cid`) VALUES (1630090627736408068, 'qqq1w', 'kdsjlsfjieosjfiosjdfo', 'eeeee', '2023-02-03 00:00:00', 2);
COMMIT;

-- ----------------------------
-- Table structure for t_channel
-- ----------------------------
DROP TABLE IF EXISTS `t_channel`;
CREATE TABLE `t_channel` (
  `id` bigint(20) NOT NULL,
  `channel_name` varchar(50) DEFAULT NULL,
  `create_time` datetime DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

-- ----------------------------
-- Records of t_channel
-- ----------------------------
BEGIN;
INSERT INTO `t_channel` (`id`, `channel_name`, `create_time`) VALUES (1, '头条', '2023-02-27 17:27:14');
INSERT INTO `t_channel` (`id`, `channel_name`, `create_time`) VALUES (2, '头七', '2023-02-27 17:27:14');
COMMIT;

SET FOREIGN_KEY_CHECKS = 1;

1.5后台的编写

1.5.1实体类的编写

package demo.entity;

import lombok.Data;

@Data
public class Article {
    private Long id;
    private String title;
    private String logo;
    private String descn;
    private String createTime;
    private Long cid;
}

1.5.2Mapper层的编写

package demo.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import demo.entity.Article;
import org.apache.ibatis.annotations.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ArticleMapper extends BaseMapper<Article> {

    Page<Article> selectByPage(Page<Article> page, @Param("title") String title);
}

1.5.3Mapper.xml的编写

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="demo.mapper.ArticleMapper">
    <select id="selectByPage" resultType="Article">
        select * from t_article where title like '%${title}%'
    </select>
</mapper>

1.5.4Controller层的编写

package demo.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import demo.entity.Article;
import demo.mapper.ArticleMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
public class ArticleController {

    @Autowired
    private ArticleMapper articleMapper;

    @GetMapping("/list")
    public Page<Article> findAll(Long pageIndex, Long pageSize){
        Page<Article> page = articleMapper.selectPage(new Page(pageIndex, pageSize), null);
        return page;
    }

    @GetMapping("/list_custom")
    public Page<Article> customFindAll(Long pageIndex, Long pageSize, String title){
        Page<Article> page = articleMapper.selectByPage(new Page(pageIndex, pageSize), title);
        return page;
    }
}

前端开发

2.1html代码

	<div class="container" id="app">
        <table class="table table-striped">
            <caption>文章列表</caption>
            <thead>
            <tr>
                <th align="center">编号</th>
                <th align="center">标题</th>
                <th align="center">描述</th>
                <th align="center">发布时间</th>
                <th align="center">操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="art in articleList">
                <td>{{art.id}}</td>
                <td>{{art.title}}</td>
                <td>{{art.descn}}</td>
                <td>{{art.createTime}}</td>
                <td align="center">
                    <button class="btn btn-link" style="margin-right: 10px;">修改</button>
                    <button class="btn btn-link">删除</button>
                </td>
            </tr>
            </tbody>
        </table>
        <ul class="pagination" v-for="p in pageCnt">
            <li v-if="p == pageIndex" class="active"><a href="#" @click="doGo(p)">{{p}}</a></li>
            <li v-else="p == pageIndex"><a href="#" @click="doGo(p)">{{p}}</a></li>
        </ul>
    </div>

2.2JS代码

	<script>
        new Vue({
            el: '#app',
            data: {
                articleList: null,
                //用于分页
                pageIndex: 1, //页码
                pageSize: 3, //每页显示的条数
                pageTotal: 0, //总条数
                pageCnt: 0 //总页数
            },
            methods: {
                requestArticleList(){
                    axios.get("http://localhost:8070/list?pageIndex="+this.pageIndex+"&pageSize="+this.pageSize).then(res => {
                        console.log(res.data)
                        this.articleList = res.data.records
                        this.pageCnt = res.data.pages
                        this.pageTotal = res.data.total
                        this.pageIndex = res.data.current
                        this.pageSize = res.data.size
                    })
                },
                doGo(p){
                    this.pageIndex = p
                    this.requestArticleList()
                }
            },
            created: function () {
                this.requestArticleList()
            }
        })
    </script>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

PageHelper+BootStrap+Vue+axios实现分页功能 的相关文章

随机推荐

  • 磁盘设备类型获取函数

    将该部分内容保存到 cpp文件中可直接编译运行 用于辨别驱动器的类型 define MEDIA INFO SIZE sizeof GET MEDIA TYPES 15 sizeof DEVICE MEDIA INFO define IOCT
  • JAVA获取上一年的日期_java获取日期,前一年,前一月,前一周

    SimpleDateFormat format new SimpleDateFormat yyyy MM dd HH mm ss Calendar calendar Calendar getInstance 现在日期 String now
  • vue区分单双击事件

    基本思路 利用setTimeout gt 200 使单击事件在200s后再执行 如果200s内触发了双击事件 则使用clearTimeout this timeOut 清除该计时器 取消单击事件的执行 执行双击事件 代码如下 定义变量 da
  • 每日一练——Python基础(七)

    请设计一个好友管理系统 每个功能都对应一个序号 用户可根据提示 请输入您的选项 选择序号执行相应的操作 包括 1 添加好友 用户根据提示 请输入要添加的好友 输入要添加好友的姓名 添加后会提示 好友添加成功 2 删除好友 用户根据提示 请输
  • Accurate Scale Estimation for Robust Visual Tracking 学习笔记:

    Accurate Scale Estimation for Robust Visual Tracking DSST学习笔记 尺度变化是跟踪中比较基础和常见的问题 目标变小 跟踪器就会吸收大量没有用的背景信息 目标过大 跟踪器就会丢失很多特征
  • HDFS的block和切片(split)的联系和区别

    lt 1 gt 联系 HDFS的block和切片 split 的大小相等 lt 2 gt 区别 1 HDFS存储数据在数据节点上 block是数据节点储存数据的一个个单位 2 split是把block切分而成的虚拟定义 3 split是Ma
  • 华为机试-HJ1 字符串最后一个单词的长度-C语言、python

    刷题第一步 熟悉输入输出及基本套路 前言 题目描述 C语言 题解1 fgets 题解2 scanf 题解3 gets python 题解1 题解2 参考解析 方法一 使用split 直接返回长度 方法二 逐位遍历找空格 前言 本文主要用于个
  • Docker中成功安装修罗Xiunobbs论坛步骤

    组成 php7 mysql5 7 xiunobbs4 04 nginx 1 Pull镜像 docker pull nginx docker pull docker io centos mysql 57 centos7 docker pull
  • Unity动画机制 Animator与Animator Controller教程

    Chinar blog www chinar xin Unity动画机制 Animator Animation 本文提供全流程 中文翻译 Chinar 的初衷是将一种简单的生活方式带给世人 使有限时间 具备无限可能 Chinar 心分享 心
  • SystemC 官方example 代码的静态分析思路与示例 —— 示例项目:TLM at_1_phase

    一 分析TLM2示例的基本流程方法 1 从sc main 开始 发现各个模块类的内部重要模块 以及对外连接的public端口或socket 理清基本has和is关系 2 看顶层类之成员类的构造函数 理清模块类的端口连接关系 socket是稍
  • Jmeter --- time函数生成时间戳

    一 元件位置 Tools 函数助手对话框 二 生成时间戳 1 未作处理的时间戳 2 除以1000 得到少三位数的时间戳
  • Python基本函数:plot()

    Python画图主要用到 matplotlib 库 而具体来说则是matplotlib下的 pylab 和 pyplot 这两个子库 这两个库可以满足基本的画图需求 下面我们只讨论 pyplot库 具体参数可以参看 官方文档 1 plt p
  • for循环python爬虫_轻松领悟for循环,做一款Python版手账

    https www xin3721 com eschool pythonxin3721 Hello 小数先生粗线啦 今天教大家制作一款Pyhon版手账 先看下手账效果 文中最后有手账代码 Python手账 for in 循环语句 for循环
  • 2-2.vue的实例属性:data

    2 2 vue的实例属性 data data属性的作用 data属性的作用是存储vue实例或组件里面的数值 在vue的实例中它是以一个对象的方式 多个键值对 在组件中它是一个函数 通过函数返回一个对象 data在vue的实例里面使用 1 代
  • 锻炼思维小题目

    第一章 假设法 一个真实的假设往往可以让事实呈现眼前 让真理浮出水面 一个人如果做什么事都可以让其思维以这些假设前提为基础 那么他便能真真正正地活在NLP里而不会陷入困境 他的人生也就会有更大地进步和提升 初级题 1 如何问问题 有甲 乙两
  • 人工智能深度学习Caffe框架介绍,优秀的深度学习架构

    人工智能深度学习Caffe框架介绍 优秀的深度学习架构 在深度学习领域 Caffe框架是人们无法绕过的一座山 这不仅是因为它无论在结构 性能上 还是在代码质量上 都称得上一款十分出色的开源框架 更重要的是 它将深度学习的每一个细节都原原本本
  • 什么是DMA

    什么是DMA 当我们向计算机中加入了一块新的声卡或其它适配卡时 安装程序可能会提醒我们应该选择一个DMA通道 那DMA是什么呢 DMA Direct Memory Access 即直接存储器存取 是一种快速传送数据的机制 数据传递可以从适配
  • const类对象的用法

    寻找了一下网上const类对象的用法 因为之前做oj题目的时候一直报错 Problem D 平面上的点 Point类 VI Time Limit 1 Sec Memory Limit 4 MB Submit 5109 Solved 2254
  • 170810 Python-封装RouterScan的DLL

    1625 5 王子昂 总结 2017年8月10日 连续第312天总结 A RouterScan Python封装 B 在老师的指导下验证了ScanRouter的参数应该是结构体的指针 而不是句柄 那么封装可以通过构造一个相同的结构体传入来完
  • PageHelper+BootStrap+Vue+axios实现分页功能

    PageHelper BootStrap Vue axios实现分页功能 效果展示 技术栈 前端技术 Vue2 5 16 axios BootStrap3 3 7 后端技术 SpringBoot2 7 9 MyBatisPlus3 5 1