org.onetwo.common.data.AbstractDataResult Maven / Gradle / Ivy
package org.onetwo.common.data;
import org.onetwo.common.utils.Assert;
import org.onetwo.common.utils.StringUtils;
@SuppressWarnings("serial")
abstract public class AbstractDataResult implements Result{
public static final String SUCCESS = "SUCCESS";
public static final String ERROR = "ERROR";
public static final String ERR = "ERR";
public static final String EXCEPTION_POSTFIX = "Exception";
private String code = SUCCESS;//0,1;
private String message;//
/***
*
面向某些领域时,指示客户端是否只提取result里的data作为返回结果
*/
private boolean extractableData = false;
public AbstractDataResult(){
this.code = SUCCESS;
}
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
/****
* 本次操作请求是否成功(没有发生任何异常)
* @return
*/
public boolean isSuccess(){
return !isError();
}
public boolean isError(){
if(code!=null){
return code.endsWith(EXCEPTION_POSTFIX) ||
code.toUpperCase().startsWith(ERR) ||
code.toUpperCase().startsWith(ERROR);
}else{
return false;
}
}
public boolean isExtractableData() {
return extractableData;
}
/***
* 指示客户端是否只提取result里的data作为返回结果
* @param extractableData
*/
public void setExtractableData(boolean extractableData) {
this.extractableData = extractableData;
}
/****
* 指示客户端是否只显示message内容即可
* @return
*/
public boolean isMessageOnly() {
return StringUtils.isNotBlank(message) && getData()==null;
}
public static class LazyResult extends AbstractDataResult
© 2015 - 2025 Weber Informatics LLC | Privacy Policy