| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- package com.chuanghai.attendance.common.utils;
- import java.io.Serializable;
- /**
- * @Author: codingliang
- * @Description: 接口统一返回
- * @Date: 2021-04-29 12:10
- * @Version: V1.0
- **/
- public class CommonResult<T> extends BaseResult implements Serializable {
- private static final long serialVersionUID = 3616484754899974346L;
- public static CommonResult ok() {
- return ok("1", "执行成功");
- }
- public static <T> CommonResult<T> ok(String code, String msg) {
- return baseCreate(code, msg, true);
- }
- public static CommonResult fail() {
- return fail("-1", "执行失败");
- }
- public static CommonResult fail(String code, String msg) {
- return baseCreate(code, msg, false);
- }
- private static <T> CommonResult<T> baseCreate(String code, String msg, boolean success) {
- CommonResult result = new CommonResult();
- result.setCode(code);
- result.setSuccess(success);
- result.setMessage(msg);
- return result;
- }
- public CommonResult<T> setResult(T data) {
- this.setData(data);
- return this;
- }
- public T getData() {
- return (T) super.getData();
- }
- public static CommonResult result(String code, String msg, Boolean b) {
- return baseCreate(code, msg, b);
- }
- }
|