当前位置:网站首页>山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
2022-04-23 19:30:00 【番茄炒蛋不加蛋!】
目录
一、前后端传输数据的封装
为了使前后端的数据交互更为方便安全,我对前端传来的数据以及后端返回的数据做了封装等处理。
具体实现步骤内容如下:
1.1 Result.java
接口统一返回包装类
主要有三部分组成:
code:状态码,在Contants.java类中定义了常见的状态
mag:返回消息,如登录成功,系统错误等
data:返回数据
/**
* 接口统一返回包装类
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Result {
private String code;
private String msg;
private Object data;
public static Result success() {
return new Result(Constants.CODE_200, "", null);
}
public static Result success(Object data) {
return new Result(Constants.CODE_200, "", data);
}
public static Result error(String code, String msg) {
return new Result(code, msg, null);
}
public static Result error() {
return new Result(Constants.CODE_500, "系统错误", null);
}
}
1.2 Contants.java
状态码的常见取值:
public interface Constants {
String CODE_200 = "200"; //成功
String CODE_401 = "401"; // 权限不足
String CODE_400 = "400"; // 参数错误
String CODE_500 = "500"; // 系统错误
String CODE_600 = "600"; // 其他业务异常
String DICT_TYPE_ICON = "icon";
}
1.3 前端对数据的预处理
后端返回Result类型的数据,前端在request.js进行处理
处理代码如下:
request.interceptors.response.use(
response => {
let res = response.data;
// 如果是返回的文件
if (response.config.responseType === 'blob') {
return res
}
// 兼容服务端返回的字符串数据
if (typeof res === 'string') {
res = res ? JSON.parse(res) : res
}
// 当权限验证不通过的时候给出提示
if (res.code === '401') {
// ElementUI.Message({
// message: res.msg,
// type: 'error'
// });
router.push("/login")
}
return res;
},
error => {
console.log('err' + error) // for debug
return Promise.reject(error)
}
二、论坛功能设计
论坛作为用户讨论交流的地方是必不可少的。
2.1 界面
前端的设计如下,每条说说放置在一张卡片上,写有标题、内容、作者和发表时间

2.2 ForumCard.vue
<template>
<div class="main">
<el-row>
<el-col :span="16">
<div>
<el-input
style="width: 60%"
placeholder="请输入关键词"
suffix-icon="el-icon-search"
v-model="search" />
</div>
</el-col>
<el-col :span="2">
<div>
<el-button type="info" @click="load" plain>搜索</el-button>
</div>
</el-col>
<el-col :span="2">
<div>
<el-button type="info" @click="goto_write" plain>发布</el-button>
</div>
</el-col>
<el-col :span="4"><div></div></el-col>
</el-row>
<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>
</div>
</template>
版权声明
本文为[番茄炒蛋不加蛋!]所创,转载请带上原文链接,感谢
https://blog.csdn.net/m0_52100140/article/details/124239108
边栏推荐
- C6748 software simulation and hardware test - with detailed FFT hardware measurement time
- 【h264】libvlc 老版本的 hevc h264 解析,帧率设定
- Why is the hexadecimal printf output of C language sometimes with 0xff and sometimes not
- 一个简单的(基于redisson的)分布式同步工具类封装
- MySQL syntax collation (3)
- Deep learning -- Summary of Feature Engineering
- Build intelligent garbage classification applet based on Zero
- TI DSP的 FFT与IFFT库函数的使用测试
- Coordinate conversion WGS-84 to gcj-02 and gcj-02 to WGS-84
- Problems caused by flutter initialroute and home
猜你喜欢

C6748 软件仿真和硬件测试 ---附详细FFT硬件测量时间

MySQL syntax collation (5) -- functions, stored procedures and triggers

Common SQL commands

No, some people can't do the National Day avatar applet (you can open the traffic master and earn pocket money)

Unity创建超写实三维场景的一般步骤

深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件

2021-2022-2 ACM集训队每周程序设计竞赛(8)题解

Zero base to build profit taking away CPS platform official account
![[报告] Microsoft :Application of deep learning methods in speech enhancement](/img/c1/7bffbcecababf8dabf86bd34ab1809.png)
[报告] Microsoft :Application of deep learning methods in speech enhancement

An algorithm problem was encountered during the interview_ Find the mirrored word pairs in the dictionary
随机推荐
Distinction between pointer array and array pointer
Go three ways to copy files
MySQL syntax collation (2)
Translation of audio signal processing and coding: Preface
Openlayers draw rectangle
Machine learning catalog
Kubernetes入门到精通-KtConnect(全称Kubernetes Toolkit Connect)是一款基于Kubernetes环境用于提高本地测试联调效率的小工具。
Audio signal processing and coding - 2.5.3 the discrete cosine transform
How to uninstall easyton
Gossip: on greed
The flyer realizes page Jump through routing routes
深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件
Shanda Wangan shooting range experimental platform project - personal record (V)
Web Security
ESP8266-入门第一篇
Class loading mechanism
The usage of slice and the difference between slice and array
Shanda Wangan shooting range experimental platform project - personal record (IV)
JVM的类加载过程
IIS data conversion problem: 16bit to 24bit