当前位置:网站首页>山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
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
边栏推荐
- Openlayers 5.0 reload the map when the map container size changes
- 深度分析数据恢复原理——那些数据可以恢复那些不可以数据恢复软件
- The flyer realizes page Jump through routing routes
- Gossip: on greed
- Easy mock local deployment (you need to experience three times in a crowded time. Li Zao will do the same as me. Love is like a festival mock)
- ArcGIS JS API dojoconfig configuration
- Audio signal processing and coding - 2.5.3 the discrete cosine transform
- 山大网安靶场实验平台项目—个人记录(四)
- MySQL数据库 - 单表查询(一)
- Decompile and get the source code of any wechat applet - just read this (latest)
猜你喜欢
Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
Shanda Wangan shooting range experimental platform project - personal record (IV)
Distinction between pointer array and array pointer
山大网安靶场实验平台项目—个人记录(四)
Shanda Wangan shooting range experimental platform project - personal record (V)
Kubernetes入门到精通-裸机LoadBalence 80 443 端口暴露注意事项
ArcMap publishing slicing service
[报告] Microsoft :Application of deep learning methods in speech enhancement
Why is PostgreSQL about to surpass SQL Server?
Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
随机推荐
The difference between underline and dot of golang import package
@MapperScan与@Mapper
Prefer composition to inheritance
Use of fluent custom fonts and pictures
Intuitive understanding of the essence of two-dimensional rotation
JS controls the file type and size when uploading files
点云数据集常用处理
Speculation on the way to realize the smooth drag preview of video editing software
Deep learning -- Summary of Feature Engineering
Web Security
Some ideas about time-consuming needs assessment
Audio editing generation software
Strange passion
UML类图几种关系的总结
Class loading mechanism
White screen processing method of fulter startup page
Why is the hexadecimal printf output of C language sometimes with 0xff and sometimes not
Hot reload debugging
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
goroutine