Java返回结果工具类Result

package com.xcx.exam.utils;

import lombok.Data;

@Data
public class Result {
private Integer code;

private String msg;


private T data;

}

package com.xcx.exam.utils;

public class ResultUtils {

public static Result success(Object obj) {
    return getResult(ResultEnum.SUCCESS, obj);
}

public static Result success() {
    return getResult(ResultEnum.SUCCESS, null);
}



public static Result getResult(ResultEnum re) {
    return getResult(re, null);
}

public static Result getResult(ResultEnum re, Object obj) {
    return getResult(re.getCode(), re.getMessage(), obj);
}

public static Result getResult(Integer code, String msg) {
    return getResult(code, msg, null);
}


public static Result getResult(Integer code, String msg, Object obj) {
    Result result = new Result();
    result.setCode(code);
    result.setMsg(msg);
    result.setData(obj);
    return result;
}

}

package com.xcx.exam.utils;

public enum ResultEnum implements CommonEnum {

SUCCESS(200, "成功"),
UNVALID(3000, null),
UNAUTH_POST(3012, "失败"),
MOBILE_UNAUTH(3060, "已投票"),
MOBILE_AUTHED(3061, "手机号已验证"),
MOBILE_UNVALID(3062, "手机号不合法"),
MACHINE_UNVALID(3070, "提货柜编号不存在"),
VERIFICATION_ERROR(4000, "验证码不匹配"),
VERIFICATION_NULL(4003, "验证码过期或未发送"),
CODE_NULL(4008, "code不存在"),
CODE_ERROR(4009, "code过期"),
OPENID_NULL(4010, "openId不存在"),
OPENID_ERROR(4011, "openId错误"),
MOBILE_BLANK(4025, "手机号为空"),
MOBILE_INVALID(4026, "手机号格式不正确"),
PARAMS_BLANK(4027, "参数为空"),
ERROR(5000, null);

private Integer code;

private String message;

ResultEnum(Integer code, String message) {
    this.code = code;
    this.message = message;
}


public Integer getCode() {
    return code;
}


public String getMessage() {
    return message;
}

}

package com.xcx.exam.utils;

/**

  • @version 1.0.0
  • @description 公共枚举接口
    */
    public interface CommonEnum {
    Number getCode();
    String getMessage();
    }

@ApiResponses({
@ApiResponse(code = 200,message = “查询成功”),
@ApiResponse(code = 3012,message = “失败”),
})
@PostMapping(value = “/list”)
public Result list(@Valid HttpSession session){//@RequestBody
List s = evalService.selectAll();
if (s!=null){
return ResultUtils.success(s);
}
return ResultUtils.getResult(ResultEnum.UNAUTH_POST);//帐户不存在;
}

©️2020 CSDN 皮肤主题: 游动-白 设计师: 上身试试 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值