当前位置:网站首页>Status code encapsulation -- reprint
Status code encapsulation -- reprint
2022-04-21 20:07:00 【Daimeng Xiaoxin @ Yuanjie】
List of articles
Reprint jeebase-WANGLEI And make supplement
One . Constant encapsulation
/** * @author jeebase-WANGLEI * @ClassName: PublicResultConstant * @Description: TODO * @date 2018 year 5 month 18 Japan Afternoon 11:49:45 */
public enum ResponseConstant {
/** * success 20x */
// success The server has successfully processed the request . Usually , This means that the server provides the requested web page .
SUCCESS_200(200, "success"),
// Created The request succeeded and the server created a new resource .
SUCCESS_201(201, "success"),
// Accepted Request accepted by server , But not yet processed .
SUCCESS_202(202, " Not yet processed "),
// Reset Content The server successfully processed the request , But nothing is returned .
SUCCESS_205(205, " The server successfully processed the request , But nothing is returned "),
/** * abnormal 40x */
// Wrong request The server does not understand the syntax of the request .
FAILED_400(400, " Wrong request "),
// - unauthorized Request for authentication . token Be overdue
UNAUTHORIZED_401(401, " unauthorized "),
// prohibit Server rejects request .
FAILED_403(403, " Server rejects request "),
// Not found The server could not find the requested page .
FAILED_404(404, " The server could not find the requested page "),
// 408- request timeout Server timed out waiting for request .
FAILED_408(408, " request timeout "),
/** * Server error 50x */
// Server internal error
SERVER_ERROR_500(500," Server internal error "),
// Server not available The server is currently unavailable ( Maintenance due to overload or shutdown ).
SERVER_ERROR_503(503," Server not available "),
/** * operation failed */
ERROR(90000000, " operation failed "),
/** * Parameter error */
PARAM_ERROR(90000003, " Parameter error "),
/** * Verification code error */
INVALID_RE_VCODE(10000011, " Verification code error "),
/** * Wrong user name or password */
INVALID_USERNAME_PASSWORD(10000003, " Wrong account or password "),
/** * */
INVALID_RE_PASSWORD(10000010, " The two passwords are not the same "),
/** * Wrong user name or password */
INVALID_PASSWORD(10000009, " The old password is wrong "),
/** * repeat of user name */
USERNAME_ALREADY_IN(10000002, " The user already exists "),
/** * The user doesn't exist */
INVALID_USER(10000001, " The user doesn't exist "),
/** * The character doesn't exist */
INVALID_ROLE(10000004, " The character doesn't exist "),
/** * The character doesn't exist */
ROLE_USER_USED(10000008, " Role in use , Not delete "),
/** * Parameter error - Already exists */
INVALID_PARAM_EXIST(10000005, " Request parameter already exists "),
/** * Parameter error */
INVALID_PARAM_EMPTY(10000006, " The request parameter is empty "),
/** * No authority */
USER_NO_PERMITION(10000007, " The current user does not have permission for this interface ");
public int result;
public String msg;
ResponseConstant(int result, String msg) {
this.result = result;
this.msg = msg;
}
public int getResult() {
return result;
}
public void setResult(int result) {
this.result = result;
}
public String getMsg() {
return msg;
}
public void setMsg(String msg) {
this.msg = msg;
}
}
Two . Return status code
Reprint Acerola;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
/** * @author Acerola */
@Data
@AllArgsConstructor
public class Result<T> {
private int code;
private String msg;
private T data;
public Result() {
}
public Result(T data) {
this.data = data;
}
/** * Return to success */
public Result<T> success() {
return success(" Successful operation !");
}
/** * Return to success */
public Result<T> success(String message) {
return success(200, message);
}
/** * File upload succeeded * * @param data * @param * @return */
public Result<T> fileSuccess(T data) {
Result<T> result = new Result<>(data);
result.setCode(0);
result.setMsg(" success ");
return result;
}
/** * Return to success */
public Result<T> success(ResponseConstant constant) {
return success(constant.getResult(), constant.getMsg());
}
/** * Return to success */
public Result<T> success(int code, String message) {
this.setCode(code);
this.setMsg(message);
return this;
}
/** * Return failed */
public Result<T> error() {
return error(" operation failed !");
}
/** * Return failed */
public Result<T> error(String messag) {
return error(500, messag);
}
/** * Return failed */
public Result<T> error(int code, String message) {
return success(code, message);
}
/** * Return information */
public Result<T> error(ResponseConstant constant) {
return success(constant.getResult(), constant.getMsg());
}
/** * Put in object */
public Result<T> put(T object) {
this.setData(object);
return this;
}
}
版权声明
本文为[Daimeng Xiaoxin @ Yuanjie]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204211929589669.html
边栏推荐
- 创建索引的注意事项
- 你的独立站转化率低?三个小技巧帮助提高转化率
- How does the Mui tab realize circular rotation
- MySQL修改root用户密码
- Ali IOT
- How to restore the deleted photos? Four schemes, which is the official guide
- Solutions informatiques pour les entreprises manufacturières haut de gamme, maintenance prédictive de l'équipement, des données et du système de la plate - forme de commerce électronique industriel
- [play with lighthouse] use Tencent cloud to realize wechat payment business in light weight
- JUC queue interface and its implementation class
- PostgreSql postgres_fdw
猜你喜欢
随机推荐
STL容器(一)--vector
Three implementation methods of quick sorting
How does the Mui tab realize circular rotation
The timer class of version C is accurate to microseconds and retains one decimal place after seconds. It supports the output of year, month, day, hour, minute and second with units
[play with lighthouse] use Tencent cloud to realize wechat payment business in light weight
创建索引的注意事项
Interesting souls are the same. It takes only 2 steps to slide the computer off
StopWatch
docker中安装MySQL、MSSQL、Oracle、MongDB、Redis集合
JUC queue interface and its implementation class
PostgreSql postgres_fdw
Vtkjs introduction
How to let the back door of the network card kill a system and let you know how powerful the network card is
[CTF. Show. Reverse] Abstract Language
The difference between PE P / E ratios
测试while(u--);和while(u)u--;的区别
SAP PS section 12 network cost plan
824. Goat Latin
Use of auto keyword
Introduction to applet project files








