5 changed files with 271 additions and 119 deletions
@ -0,0 +1,21 @@ |
|||
package com.yxt.anrui.utils; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2021/6/16 10:50 |
|||
* @description |
|||
*/ |
|||
|
|||
public class HttpStatus { |
|||
|
|||
/** |
|||
* 操作成功 |
|||
*/ |
|||
public static final int SUCCESS = 200; |
|||
|
|||
/** |
|||
* 系统内部错误 |
|||
*/ |
|||
public static final int ERROR = 500; |
|||
|
|||
} |
@ -0,0 +1,44 @@ |
|||
/********************************************************* |
|||
********************************************************* |
|||
******************** ******************* |
|||
************* ************ |
|||
******* _oo0oo_ ******* |
|||
*** o8888888o *** |
|||
* 88" . "88 * |
|||
* (| -_- |) * |
|||
* 0\ = /0 * |
|||
* ___/`---'\___ * |
|||
* .' \\| |// '. *
|
|||
* / \\||| : |||// \ *
|
|||
* / _||||| -:- |||||- \ * |
|||
* | | \\\ - /// | | *
|
|||
* | \_| ''\---/'' |_/ | * |
|||
* \ .-\__ '-' ___/-. / * |
|||
* ___'. .' /--.--\ `. .'___ * |
|||
* ."" '< `.___\_<|>_/___.' >' "". * |
|||
* | | : `- \`.;`\ _ /`;.`/ - ` : | | * |
|||
* \ \ `_. \_ __\ /__ _/ .-` / / * |
|||
* =====`-.____`.___ \_____/___.-`___.-'===== * |
|||
* `=---=' * |
|||
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ * |
|||
*********__佛祖保佑__永无BUG__验收通过__钞票多多__********* |
|||
*********************************************************/ |
|||
package com.yxt.anrui.utils; |
|||
|
|||
/** |
|||
* Project: yxt-common <br/> |
|||
* File: IResultCodeMsg.java <br/> |
|||
* Class: com.yxt.common.core.result.IResultCodeMsg <br/> |
|||
* Description: <描述类的功能>. <br/> |
|||
* Copyright: Copyright (c) 2011 <br/> |
|||
* Company: https://gitee.com/liuzp315 <br/>
|
|||
* Makedate: 2021/9/11 下午11:00 <br/> |
|||
* |
|||
* @author popo |
|||
* @version 1.0 |
|||
* @since 1.0 |
|||
*/ |
|||
public interface IResultCodeMsg { |
|||
String getCode(); |
|||
String getMsg(); |
|||
} |
@ -1,104 +0,0 @@ |
|||
package com.yxt.anrui.utils; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* @author dimengzhe |
|||
* @date 2020/12/2 10:07 |
|||
* @description |
|||
*/ |
|||
|
|||
public class R<T> implements Serializable { |
|||
|
|||
private static final long serialVersionUID = 1L; |
|||
|
|||
/** |
|||
* 成功 |
|||
*/ |
|||
public static final int SUCCESS = Constants.SUCCESS; |
|||
|
|||
/** |
|||
* 失败 |
|||
*/ |
|||
public static final int FAIL = Constants.FAIL; |
|||
|
|||
private int code; |
|||
|
|||
private String msg; |
|||
private boolean success; |
|||
|
|||
public boolean isSuccess() { |
|||
return success; |
|||
} |
|||
|
|||
public void setSuccess(boolean success) { |
|||
this.success = success; |
|||
} |
|||
|
|||
private T data; |
|||
|
|||
public static <T> R<T> ok() { |
|||
return restResult(null, SUCCESS, null, true); |
|||
} |
|||
|
|||
public static <T> R<T> ok(T data) { |
|||
return restResult(data, SUCCESS, null, true); |
|||
} |
|||
|
|||
public static <T> R<T> ok(T data, String msg) { |
|||
return restResult(data, SUCCESS, msg, true); |
|||
} |
|||
|
|||
public static <T> R<T> fail() { |
|||
return restResult(null, FAIL, null, false); |
|||
} |
|||
|
|||
public static <T> R<T> fail(String msg) { |
|||
return restResult(null, FAIL, msg, false); |
|||
} |
|||
|
|||
public static <T> R<T> fail(T data) { |
|||
return restResult(data, FAIL, null, false); |
|||
} |
|||
|
|||
public static <T> R<T> fail(T data, String msg) { |
|||
return restResult(data, FAIL, msg, false); |
|||
} |
|||
|
|||
public static <T> R<T> fail(int code, String msg) { |
|||
return restResult(null, code, msg, false); |
|||
} |
|||
|
|||
private static <T> R<T> restResult(T data, int code, String msg, boolean success) { |
|||
R<T> apiResult = new R<>(); |
|||
apiResult.setCode(code); |
|||
apiResult.setData(data); |
|||
apiResult.setMsg(msg); |
|||
apiResult.setSuccess(success); |
|||
return apiResult; |
|||
} |
|||
|
|||
public int getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public void setCode(int code) { |
|||
this.code = code; |
|||
} |
|||
|
|||
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; |
|||
} |
|||
} |
@ -0,0 +1,191 @@ |
|||
package com.yxt.anrui.utils; |
|||
|
|||
import java.io.Serializable; |
|||
|
|||
/** |
|||
* Project: yxt-common-core <br/> |
|||
* File: ResultBean.java <br/> |
|||
* Class: com.yxt.common.core.result.ResultBean <br/> |
|||
* Description: 通过接口、Rest、逻辑处理执行后的结果信息. <br/> |
|||
* Copyright: Copyright (c) 2011 <br/> |
|||
* Company: https://gitee.com/liuzp315 <br/>
|
|||
* Makedate: 2020/8/4 0:51 <br/> |
|||
* |
|||
* @author liupopo |
|||
* @version 1.0 |
|||
* @since 1.0 |
|||
*/ |
|||
public class ResultBean<T> implements Serializable { |
|||
private static final long serialVersionUID = 4529658978692424234L; |
|||
|
|||
private long timestamp = System.currentTimeMillis(); |
|||
|
|||
public long getTimestamp() { |
|||
return timestamp; |
|||
} |
|||
|
|||
// 是否成功
|
|||
private boolean success; |
|||
|
|||
// 消息 返回结果的说明
|
|||
private String msg; |
|||
|
|||
// 结果状态码
|
|||
private String code; |
|||
|
|||
// 数据
|
|||
private T data; |
|||
|
|||
private String message; |
|||
|
|||
public String getMessage() { |
|||
return message; |
|||
} |
|||
|
|||
public ResultBean<T> setMessage(String message) { |
|||
this.message = message; |
|||
return this; |
|||
} |
|||
|
|||
public ResultBean() { |
|||
} |
|||
|
|||
public ResultBean(boolean success) { |
|||
this.success = success; |
|||
} |
|||
|
|||
public ResultBean(boolean success, String msg) { |
|||
this.success = success; |
|||
this.msg = msg; |
|||
} |
|||
|
|||
public ResultBean(boolean success, String msg, String code) { |
|||
this.success = success; |
|||
this.msg = msg; |
|||
this.code = code; |
|||
} |
|||
|
|||
public ResultBean(T data) { |
|||
this.success = true; |
|||
this.data = data; |
|||
} |
|||
|
|||
public ResultBean(String code, T data) { |
|||
this.success = true; |
|||
this.code = code; |
|||
this.data = data; |
|||
} |
|||
|
|||
public ResultBean(String code, String msg, T data) { |
|||
this.success = true; |
|||
this.code = code; |
|||
this.msg = msg; |
|||
this.data = data; |
|||
} |
|||
|
|||
public boolean getSuccess() { |
|||
return success; |
|||
} |
|||
|
|||
public ResultBean<T> setSuccess(boolean success) { |
|||
this.success = success; |
|||
return this; |
|||
} |
|||
|
|||
public String getMsg() { |
|||
return msg; |
|||
} |
|||
|
|||
public ResultBean<T> setMsg(String msg) { |
|||
this.msg = msg; |
|||
return this; |
|||
} |
|||
|
|||
public String getCode() { |
|||
return code; |
|||
} |
|||
|
|||
public ResultBean<T> setCode(String code) { |
|||
this.code = code; |
|||
return this; |
|||
} |
|||
|
|||
public T getData() { |
|||
return data; |
|||
} |
|||
|
|||
public ResultBean<T> setData(T data) { |
|||
this.data = data; |
|||
return this; |
|||
} |
|||
|
|||
public ResultBean<T> successOne() { |
|||
this.setSuccess(true); |
|||
this.setCode("0"); |
|||
this.setMessage("成功!"); |
|||
return this; |
|||
} |
|||
|
|||
public ResultBean<T> failOne() { |
|||
this.setSuccess(false); |
|||
this.setCode(String.valueOf(HttpStatus.ERROR)); |
|||
this.setMessage("操作失败!"); |
|||
return this; |
|||
} |
|||
|
|||
public ResultBean<T> success() { |
|||
this.setSuccess(true); |
|||
this.setCode(String.valueOf(HttpStatus.SUCCESS)); |
|||
this.setMsg("操作成功!"); |
|||
return this; |
|||
} |
|||
|
|||
public ResultBean<T> fail() { |
|||
this.setSuccess(false); |
|||
this.setCode(String.valueOf(HttpStatus.ERROR)); |
|||
this.setMsg("操作失败!"); |
|||
return this; |
|||
} |
|||
|
|||
public static <T> ResultBean<T> fireSuccess() { |
|||
ResultBean<T> rb = new ResultBean<T>(); |
|||
rb.setSuccess(true); |
|||
rb.setCode(String.valueOf(HttpStatus.SUCCESS)); |
|||
rb.setMsg("操作成功!"); |
|||
return rb; |
|||
} |
|||
|
|||
public static <T> ResultBean<T> fireFail() { |
|||
ResultBean<T> rb = new ResultBean<T>(); |
|||
rb.setSuccess(false); |
|||
rb.setCode(String.valueOf(HttpStatus.ERROR)); |
|||
rb.setMsg("操作失败!"); |
|||
return rb; |
|||
} |
|||
|
|||
/** |
|||
* 设置返回code及msg |
|||
* |
|||
* @param codeMsg Code和Msg的枚举 |
|||
* @return |
|||
*/ |
|||
public ResultBean<T> setCode(IResultCodeMsg codeMsg) { |
|||
this.code = codeMsg.getCode(); |
|||
this.msg = codeMsg.getMsg(); |
|||
return this; |
|||
} |
|||
|
|||
/** |
|||
* 返回失败信息,并指定结果code |
|||
* |
|||
* @param codeMsg Code和Msg的枚举 |
|||
* @return |
|||
*/ |
|||
public ResultBean<T> fail(IResultCodeMsg codeMsg) { |
|||
this.setSuccess(false); |
|||
this.code = codeMsg.getCode(); |
|||
this.msg = codeMsg.getMsg(); |
|||
return this; |
|||
} |
|||
|
|||
} |
Loading…
Reference in new issue