In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This issue of the content of the editor will bring you about the JAVA error class result class and paging result class code how to write, the article is rich in content and professional analysis and description for you, after reading this article, I hope you can get something.
The code is as follows
Public interface ErrorCode {String getCode (); String getMsg () / * * Common error code * segment: 1000010099 * / public enum CommonError implements ErrorCode {SUCCESS ("0", "success"), UNKNOWN_ERROR ("10000", "unknown error"), SYSTEM_ERROR ("10001", "system internal processing exception [% s]"), REQUEST_ERROR ("10002", "request address or parameter error"), DB_PROCESS_FAILED ("10003", "database processing failed") DATA_NOT_FOUND ("10004", "data does not exist"), PARAM_REQUIRED ("10005", "parameter is empty [% s]") Private String code; private String msg; private CommonError (String code, String msg) {this.code = code; this.msg = msg;} @ Override public String getCode () {return this.code;} @ Override public String getMsg () {return this.msg;} public ErrorCode setParams (Object...) Params) {this.msg = String.format (this.msg, params); return this;}} / * * API error code * code segment: 101000199 * * / public enum ApiError implements ErrorCode {REQUEST_EMPTY ("10100", "request data is empty"), API_NOT_EXISTS ("10102", "interface does not exist"); private String code; private String msg; private ApiError (String code, String msg) {this.code = code; this.msg = msg } @ Override public String getCode () {return this.code;} @ Override public String getMsg () {return this.msg;}
ErrorCode error = CommonError.SYSTEM_ERROR.setParams (e.getCause () .getMessage ())
Result:
Public class Result {public static final String SUCCESS = "0"; public static final String SCUCESS_MSG = "success"; private String result = SUCCESS; private String msg = SCUCESS_MSG; private T data; public Result () {} public Result (ErrorCode error, Object...) MsgParams) {this.setError (error, msgParams);} public Result (ErrorCode error) {this.setError (error);} public void setError (ErrorCode error, Object...) MsgParams) {this.result = error.getCode (); this.msg = error.getMsg (); if (msgParams! = null & & msgParams.length > 0) {this.msg = String.format (msg, msgParams);} public void setError (ErrorCode error) {this.setError (error, new Object [] {});} public String getResult () {return result;} public void setResult (String result) {this.result = result;} public String getMsg () {return msg } public void setMsg (String msg) {this.msg = msg;} public T getData () {return data;} public void setData (T data) {this.data = data;} public boolean isSuccess () {return SUCCESS.equals (result);} @ Override public String toString () {return "Result [result=" + result + ", msg=" + msg + ", data=" + data + "]";}}
PageResult:
Public class PageResult {public static final String SUCCESS = "0"; public static final String SCUCESS_MSG = "success"; private String result = SUCCESS; private String msg = SCUCESS_MSG; private Integer total = 0; private List rows = new ArrayList (); public PageResult () {} public PageResult (ErrorCode error, Object...) MsgParams) {this.setError (error, msgParams);} public PageResult (ErrorCode error) {this.setError (error);} public String getResult () {return result;} public void setResult (String result) {this.result = result;} public String getMsg () {return msg;} public void setMsg (String msg) {this.msg = msg;} public Integer getTotal () {return total;} public void setTotal (Integer total) {this.total = total;} public List getRows () {return rows } public void setRows (List rows) {this.rows = rows;} public void setError (ErrorCode error, Object...) MsgParams) {this.result = error.getCode (); this.msg = error.getMsg (); if (msgParams! = null & & msgParams.length > 0) {this.msg = String.format (msg, msgParams);}} public void setError (ErrorCode error) {this.setError (error, new Object [] {});} public boolean isSuccess () {return SUCCESS.equals (result);}}
The above is the JAVA error class result class and paging result class code shared by the editor. If you happen to have similar doubts, you might as well refer to the above analysis to understand. If you want to know more about it, you are welcome to follow the industry information channel.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.