当前位置:网站首页>山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
山东大学软件学院项目实训-创新实训-网络安全靶场实验平台(六)
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
边栏推荐
- 2021-2022-2 ACM training team weekly Programming Competition (8) problem solution
- Steps to build a deep learning environment GPU
- Go modules daily use
- 山大网安靶场实验平台项目-个人记录(五)
- How to select the third-party package of golang
- Openlayers 5.0 loading ArcGIS Server slice service
- Audio editing generation software
- Garbage collector and memory allocation strategy
- Problems caused by flutter initialroute and home
- HTTP cache - HTTP authoritative guide Chapter VII
猜你喜欢
Using oes texture + glsurfaceview + JNI to realize player picture processing based on OpenGL es
Decompile and get the source code of any wechat applet - just read this (latest)
Zero cost, zero foundation, build profitable film and television applet
Kubernetes入门到精通-KtConnect(全称Kubernetes Toolkit Connect)是一款基于Kubernetes环境用于提高本地测试联调效率的小工具。
MySQL syntax collation (4)
MySQL syntax collation (5) -- functions, stored procedures and triggers
Common SQL commands
MySQL lock
OpenHarmony开源开发者成长计划,寻找改变世界的开源新生力!
Possible root causes include a too low setting for -Xss and illegal cyclic inheritance dependencies
随机推荐
IIS data conversion problem: 16bit to 24bit
Command - sudo
[report] Microsoft: application of deep learning methods in speech enhancement
什么是消息队列
Openlayers 5.0 thermal diagram
uIP1.0 主动发送的问题理解
ArcMap publishing slicing service
A brief explanation of golang's keyword "competence"
MySQL syntax collation
Inject Autowired fields into ordinary beans
音频编辑生成软件
机器学习目录
Web Security
Shanda Wangan shooting range experimental platform project - personal record (IV)
Class loading process of JVM
A simple (redisson based) distributed synchronization tool class encapsulation
Common processing of point cloud dataset
ArcMap connecting ArcGIS Server
Virtual machine performance monitoring and fault handling tools
点云数据集常用处理