| /** | 
|  * Copyright (c) 2018 人人开源 All rights reserved. | 
|  * | 
|  * https://www.renren.io | 
|  * | 
|  * 版权所有,侵权必究! | 
|  */ | 
|   | 
| package com.zt.common.servlet; | 
|   | 
| import com.zt.common.exception.ErrorCode; | 
| import com.zt.common.utils.MessageUtils; | 
| import io.swagger.annotations.ApiModel; | 
| import io.swagger.annotations.ApiModelProperty; | 
| import lombok.Data; | 
|   | 
| import java.io.Serializable; | 
|   | 
| /** | 
|  * 响应数据 | 
|  * | 
|  * @author hehz | 
|  * @since 1.0.0 | 
|  */ | 
| @Data | 
| @ApiModel(value = "响应") | 
| public class Result<T> implements Serializable { | 
|     /** | 
|      * 编码:0表示成功,其他值表示失败 | 
|      */ | 
|     @ApiModelProperty(value = "编码:0表示成功,其他值表示失败") | 
|     private int code = 0; | 
|     /** | 
|      * 消息内容 | 
|      */ | 
|     @ApiModelProperty(value = "消息内容") | 
|     private String msg = "success"; | 
|     /** | 
|      * 响应数据 | 
|      */ | 
|     @ApiModelProperty(value = "响应数据") | 
|     private T data; | 
|   | 
|     protected Result() { | 
|     } | 
|   | 
|     public static <T> Result<T> ok() { | 
|         Result<T> result = new Result<>(); | 
|         return result; | 
|     } | 
|   | 
|     public static <T> Result<T> ok(T data) { | 
|         Result<T> result = new Result<>(); | 
|         result.setData(data); | 
|         return result; | 
|     } | 
|   | 
|     public static <T> Result<T> error() { | 
|         Result<T> result = new Result<>(); | 
|         result.code = ErrorCode.INTERNAL_SERVER_ERROR.getCode(); | 
|         result.msg = MessageUtils.getMessage(result.code); | 
|         return result; | 
|     } | 
|   | 
|     public static <T> Result<T> error(int code) { | 
|         Result<T> result = new Result<>(); | 
|         result.code = code; | 
|         result.msg = MessageUtils.getMessage(result.code); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     public static <T> Result<T> error(ErrorCode code) { | 
|         Result<T> result = new Result<>(); | 
|         result.code = code.getCode(); | 
|         result.msg = code.getMessage(); | 
|         return result; | 
|     } | 
|   | 
|   | 
|     public static <T> Result<T> error(int code, String msg) { | 
|         Result<T> result = new Result<>(); | 
|         result.code = code; | 
|         result.msg = msg; | 
|         return result; | 
|     } | 
|   | 
|     public static <T> Result<T> error(String msg) { | 
|         Result<T> result = new Result<>(); | 
|         result.code = ErrorCode.INTERNAL_SERVER_ERROR.getCode(); | 
|         result.msg = msg; | 
|         return result; | 
|     } | 
| } |