public CommonResult setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; return this; }2.为标志位flag创建两个共有静态的方法ok()和error()例如:
public static CommonResult ok(){ CommonResult commonResult = new CommonResult(); commonResult.setFlag(true); return commonResult; }
public static CommonResult error(){ CommonResult commonResult = new CommonResult(); commonResult.setFlag(false); return commonResult; }3.此时就可以进行链式编程了
CommonResult commonResult = CommonResult.error().setErrorMessage("用户名错误").setResultData("状态码");
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)