当前位置:网站首页>山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
2022-04-23 19:29:00 【番茄炒蛋不加蛋!】
目录
前言:本篇博客主要讲解论坛部分中的分页功能
一、Forum 分页功能
在论坛功能中,用户发表的说说数量会越来越多,导致在前端界面会展示越来越多,也就是说card越来越多。
为了方便阅读,提高数据库查询以及页面渲染的速度,我采用了分页方式进行渲染。
界面如下所示:
目前每页展示四条,现在共10条,所以有三页。
二、Vue分页组件——el-pagination
分页组件为<el-pagination/>,用法如下:
<el-pagination
v-model:currentPage="currentPage"
:page-size="pageSize"
:disabled="disabled"
:background="background"
layout="total, prev, pager, next"
:total="totalpage"
@size-change="handleSizeChange"
@current-change="load"
style="padding-top: 20px"
/>
初始绑定的数据为:
return {
formatTooltip,
goto_write,
search:'',
currentPage:1,
pageSize:4,
totalpage:0,
forumlist:[],
};
渲染方法为:
load(){
request.get("/forum/page",{
params:{
pageNum:this.currentPage,
pageSize:this.pageSize,
search:this.search
}
}).then(res =>{
this.forumlist=res.data.records
this.totalpage=res.data.total
})
},
渲染方法将<el-card>中所需的forumlist数据进行绑定
<el-space direction="vertical" style="text-align: left">
<el-card v-for="(forum,i) in forumlist" :key="i" class="box-card" style="width: 1200px;background-color: #99a9bf" shadow="hover">
<template #header>
<div class="card-header">
<span style="font-weight:bold">{
{ forum.title }}</span>
</div>
</template>
<div class="text item">
{
{ forum.content }}
</div>
<div class="text item" style="margin-top: 20px">
{
{ forum.username }}
</div>
<div class="text item" style="text-align: right">
{
{ forum.time }}
</div>
</el-card>
</el-space>
三、mybatis分页——selectPage
在后端代码的编写中,首先编写了实体类Forum.java
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
@Data
@TableName("forum")
public class Forum {
@TableId(type = IdType.AUTO)
private Integer forumid;
private String title;
private String content;
private Integer username;
private String time;
private Integer state;
}
ForumController.java
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sducsrp.csrp.common.Result;
import com.sducsrp.csrp.entity.Forum;
import com.sducsrp.csrp.mapper.ForumMapper;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
@RestController
@RequestMapping("/forum")
public class ForumController {
@Resource
ForumMapper forumMapper;
@GetMapping("/page")
public Result findpage(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "5") Integer pageSize,
@RequestParam(defaultValue = "") String search){
Page<Forum> forumPage=forumMapper.selectPage(new Page<>(pageNum,pageSize), Wrappers.<Forum>lambdaQuery().like(Forum::getForumid,search));
return Result.success(forumPage);
}
}
其中,最重要的代码为:
@GetMapping("/page")
public Result findpage(@RequestParam(defaultValue = "1") Integer pageNum,
@RequestParam(defaultValue = "5") Integer pageSize,
@RequestParam(defaultValue = "") String search){
Page<Forum> forumPage=forumMapper.selectPage(new Page<>(pageNum,pageSize), Wrappers.<Forum>lambdaQuery().like(Forum::getForumid,search));
return Result.success(forumPage);
}
这是mybatis的分页功能函数,兼具查询功能
参数分别问查询页数、页面大小、以及查询内容。
版权声明
本文为[番茄炒蛋不加蛋!]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_52100140/article/details/124239504
边栏推荐
- ArcMap publishing slicing service
- Summary of several relationships of UML class diagram
- 图书管理数据库系统设计
- [报告] Microsoft :Application of deep learning methods in speech enhancement
- Thoughts on the optimization of examination papers in the examination system
- MFCC: Mel频率倒谱系数计算感知频率和实际频率转换
- Garbage collector and memory allocation strategy
- Core concepts of rest
- MySQL syntax collation (3)
- Use of fluent custom fonts and pictures
猜你喜欢
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
ESP8266-入门第一篇
Unity创建超写实三维场景的一般步骤
MySQL syntax collation (3)
Grafana 分享带可变参数的链接
An idea of rendering pipeline based on FBO
优先使用组合而不使用继承
ArcMap publishing slicing service
Openharmony open source developer growth plan, looking for new open source forces that change the world!
[webrtc] add x264 encoder for CEF / Chromium
随机推荐
Use of fluent custom fonts and pictures
kibana 报错 server is not ready yet 可能的原因
深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件
The platinum library cannot search the debug process records of some projection devices
C语言的十六进制printf为何输出有时候输出带0xFF有时没有
MySQL syntax collation (2)
ArcMap connecting ArcGIS Server
[H264] hevc H264 parsing and frame rate setting of the old version of libvlc
深度学习环境搭建步骤—gpu
[report] Microsoft: application of deep learning methods in speech enhancement
MySQL lock
TI DSP的 FFT与IFFT库函数的使用测试
Encyclopedia of professional terms and abbreviations in communication engineering
What is a message queue
Garbage collector and memory allocation strategy
Application of DCT transform
Kubernetes入门到精通-裸机LoadBalence 80 443 端口暴露注意事项
Command - sudo
Speex维纳滤波与超几何分布的改写
Matlab 2019 installation of deep learning toolbox model for googlenet network