当前位置:网站首页>山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(七)
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
边栏推荐
- The flyer realizes page Jump through routing routes
- Core concepts of rest
- Kubernetes入门到精通-在 Kubernetes 上安装 OpenELB
- Class loading mechanism
- 仓库管理数据库系统设计
- [report] Microsoft: application of deep learning methods in speech enhancement
- 什么是消息队列
- ArcGIS JS API dojoconfig configuration
- Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
- FFT物理意义: 1024点FFT就是1024个实数,实际进入fft的输入是1024个复数(虚部为0),输出也是1024个复数,有效的数据是前512个复数
猜你喜欢

Is meituan, a profit-making company with zero foundation, hungry? Coupon CPS applet (with source code)

Prefer composition to inheritance

White screen processing method of fulter startup page

OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!

An idea of rendering pipeline based on FBO

MySQL syntax collation (5) -- functions, stored procedures and triggers
![[report] Microsoft: application of deep learning methods in speech enhancement](/img/c1/7bffbcecababf8dabf86bd34ab1809.png)
[report] Microsoft: application of deep learning methods in speech enhancement

Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies

山大网安靶场实验平台项目—个人记录(四)

Kubernetes入门到精通-裸机LoadBalence 80 443 端口暴露注意事项
随机推荐
Regular expressions for judging positive integers
Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
ArcMap publishing slicing service
[report] Microsoft: application of deep learning methods in speech enhancement
[transfer] summary of new features of js-es6 (one picture)
深度学习环境搭建步骤—gpu
A simple (redisson based) distributed synchronization tool class encapsulation
Virtual machine performance monitoring and fault handling tools
C6748 软件仿真和硬件测试 ---附详细FFT硬件测量时间
JS calculation time difference
Why is PostgreSQL about to surpass SQL Server?
【h264】libvlc 老版本的 hevc h264 解析,帧率设定
Kubernetes入门到精通-裸机LoadBalence 80 443 端口暴露注意事项
Zero cost, zero foundation, build profitable film and television applet
No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)
Class loading process of JVM
Physical meaning of FFT: 1024 point FFT is 1024 real numbers. The actual input to FFT is 1024 complex numbers (imaginary part is 0), and the output is also 1024 complex numbers. The effective data is
Use test of FFT and IFFT library functions of TI DSP
How to uninstall easyton
Why is the hexadecimal printf output of C language sometimes with 0xff and sometimes not