Appearance
接口设计说明书
Java后台接口
接口返回参数
java
// 返回标记:成功=0,失败=1
private int status;
// 返回信息
private String message;
// 数据
private T data;
接口返回方法
方法 | 返回http状态 | 方法返回参数 | 描述 |
---|---|---|---|
ok | 200 | 数据、状态及异常编码 | 正常 |
failed | 400 | 数据、状态及异常编码 | 请求发生错误 |
unauthorized | 401 | 数据、状态及异常编码 | 认证异常 |
forbidden | 403 | 数据、状态及异常编码 | 没有权限 |
notFound | 404 | 数据、状态及异常编码 | 请求资源不存在 |
unprocessableEntity | 422 | 数据、状态及异常编码 | 请求数据异常 |
Vue接口
Vue axios请求接口
javascript
// 后台返回状态信息
const status = Number(res.status) || 200;
// 后台返回描述信息
const message = res.data.msg || errorCode[status] || errorCode['default']
// 后台定义 424 针对令牌过期的特殊响应码
if (status === 424) {
ElMessageBox.confirm('令牌状态已过期,请点击重新登录', '系统提示', {
confirmButtonText: '重新登录',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
store.dispatch('LogOut').then(() => {
window.location.reload()
})
}).catch(() => {})
return
}
// 正常返回
if (status !== 200 || res.data.code === 1) {
if (status === 400) {
ElMessageBox({
message: i18nMessageJsons[res.data.message] || i18nMessageJsons['common_message_badRequest'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_badRequest']));
}
// 认证异常
if (status === 401) {
ElMessageBox({
message: i18nMessageJsons['common_message_unauthorized'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_unauthorized']));
}
// 没有权限
if (status === 403) {
ElMessageBox({
message: i18nMessageJsons['common_message_forbidden'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_forbidden']));
}
// 请求资源不存在
if (status === 404) {
ElMessageBox({
message: i18nMessageJsons['common_message_notFound'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_notFound']));
}
// 请求数据异常
if (status === 422) {
ElMessageBox({
message: i18nMessageJsons['common_message_unprocessableEntity'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_unprocessableEntity']));
}
// 服务访问异常
if (status === 503) {
ElMessageBox({
message: i18nMessageJsons['common_message_serviceUnavailable'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_serviceUnavailable']));
}
// 服务器内部异常
if (status === 500) {
ElMessageBox({
message: i18nMessageJsons['common_message_internalServerError'],
type: 'error'
})
return Promise.reject(new Error(i18nMessageJsons['common_message_internalServerError']));
}
// 其他异常
ElMessageBox({
message: i18nMessageJsons[message],
type: 'error'
})
return Promise.reject(new Error(message))
}
return res
}, error => {
NProgress.done()
return Promise.reject(new Error(error))
})
管理平台接口js请求参数说明
请求方式 | 参数 | 后台接收参数 | 示例 |
---|---|---|---|
GET | params : json参数 | 普通类型 Integer、String ... | String id、Integer sort |
GET | /' + id | @PathVariable("id") String Id | @PathVariable("userId") String userId |
POST | data : 对象 | @RequestBody Objuec obj | @RequestBody Goods |
goods | |||
POST | params : json参数 | 普通类型 Integer、String ... | String id、Integer sort |
PUT | data : 对象 | @RequestBody Objuec obj | @RequestBody Goods |
goods | |||
PUT | params : json参数 | 普通类型 Integer、String ... | String id、Integer sort |
DELETE | params : json参数 | 普通类型 Integer、String ... | String id、Integer sort |
DELETE | /' + id | @PathVariable("id") String Id | @PathVariable("userId") String userId |
Uni-app接口
Uni-app请求接口
javascript
uni.request({
method: method,
url: baseURL + url + paramsStr,
data: data,
header: headers,
responseType: responseType,
success: (res) => { //数据获取成功
uni.hideLoading();
const status = Number(res.status) || 200;
const message = res.data.message || errorCode[status] || errorCode['default'];
// 正常返回
if (status != 200) {
if (status === 400) {
return uni.showToast({
title: i18nMessageJsons[message] ||
i18nMessageJsons['common_message_badRequest'],
duration: 5000,
icon: 'none'
})
}
// 认证异常
if (status === 401) {
uni.reLaunch({
url:"../../pages/index/login"
})
}
// 没有权限
if (status === 403) {
return uni.showToast({
title: i18nMessageJsons[message] || i18nMessageJsons[
'common_message_forbidden'],
duration: 5000,
icon: 'none'
})
}
// 请求资源不存在
if (status === 404) {
return uni.showToast({
title: i18nMessageJsons[message] || i18nMessageJsons[
'common_message_notFound'],
duration: 5000,
icon: 'none'
})
}
// 请求数据异常
if (status === 422) {
return uni.showToast({
title: i18nMessageJsons[message] || i18nMessageJsons[
'common_message_unprocessableEntity'],
duration: 5000,
icon: 'none'
})
}
// 服务访问异常
if (status === 503) {
return uni.showToast({
title: i18nMessageJsons[message] || i18nMessageJsons[
'common_message_serviceUnavailable'],
duration: 5000,
icon: 'none'
})
}
// 服务器内部异常
if (status === 500) {
return uni.showToast({
title: i18nMessageJsons[message] || i18nMessageJsons[
'common_message_internalServerError'],
duration: 5000,
icon: 'none'
})
}
// 其他异常
return uni.showToast({
title: i18nMessageJsons[message],
duration: 5000,
icon: 'none'
})
}
resolve(res) //成功,将数据返回
},
fail: (err) => { //失败操作
uni.hideLoading();
return uni.showToast({
title: errorCode['fail'],
duration: 5000,
icon: 'none'
})
reject(err)
}
});
Uniapp 接口请求参数说明
请求方式 | 参数 | 请求头 | 后台接收参数 | 示例 |
---|---|---|---|---|
GET | params : json参数 | 'Content-Type': 'application /x-www-form-urlencoded' | 普通类型 Integer、String ... | String id、Integer sort |
GET | /' + id | 'Content-Type': 'application /x-www-form-urlencoded' | @PathVariable("id") String Id | @PathVariable("userId") String userId |
POST | data : 对象 | 'Content-Type': 'application/json' | @RequestBody Objuec obj | @RequestBody Goods goods |
POST | params : json参数 | 'Content-Type': 'application /x-www-form-urlencoded' | 普通类型 Integer、String ... | String id、Integer sort |
PUT | data : 对象 | 'Content-Type': 'application/json' | @RequestBody Objuec obj | @RequestBody Goods goods |
PUT | params : json参数 | 'Content-Type': 'application /x-www-form-urlencoded' | 普通类型 Integer、String ... | String id、Integer sort |
DELETE | params : json参数 | 'Content-Type': 'application /x-www-form-urlencoded' | 普通类型 Integer、String ... | String id、Integer sort |
DELETE | /' + id | 'Content-Type': 'application /x-www-form-urlencoded' | @PathVariable("id") String Id | @PathVariable("userId") String userId |