package com.iwatering.model;
/**
*
* 返回给客户端的状态码和状态信息
*
*
* @author ...
*
* */
public enum CommunicateCode {
OPERATION_SUCCESS(0, "操作成功"),
ADD_DATA_ERROR(1, ""),
QUERY_DATA_ERROR(2, "");
/**
* 返回状态码
* */
private int statusCode;
/**
* 返回状态信息
* */
private String statusMsg;
private CommunicateCode(int statusCode, String statusMsg) {
this.statusCode = statusCode;
this.statusMsg = statusMsg;
}
/**
* @return the statusCode
* */
public int getStatusCode() {
return statusCode;
}
/**
* @return the statusMsg
* */
public String getStatusMsg() {
return statusMsg;
}
/**
* @note
*
* 每次新增一个状态,只需要增加一个美剧元素即可,不会出现状态码和信息对应不上的调用问题。
* 一般化写法会是:
* public final int OPERATION_SUCCESS_CODE = 0;
* public final String OPERATION_SUCCESS_MSG = "..."
*
*
* @invoke convention
*
* int statusCode = CommunicateCode.OPERATION_SUCCESS.getStatusCode();
* String statusMsg = CommunicateCode.OPERATION_SUCCESS.getStatusMsg();
*
* */
}
如果字符串来自于资源id,则添加一个构造即可:
private CommunicateCode(int statusCode, int statusMsgStringId);