| | |
| | | package com.nq.common; |
| | | |
| | | import com.nq.utils.http.HttpClientRequest; |
| | | import com.nq.utils.translate.GoogleTranslateUtil; |
| | | import org.codehaus.jackson.annotate.JsonIgnore; |
| | | import org.codehaus.jackson.map.annotate.JsonSerialize; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.Serializable; |
| | | |
| | | @JsonSerialize(include = JsonSerialize.Inclusion.NON_NULL) |
| | |
| | | private int status; |
| | | private String msg; |
| | | private T data; |
| | | |
| | | |
| | | private static String LANG = "lang"; |
| | | |
| | | private ServerResponse(int status) { |
| | | this.status = status; |
| | |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), msg); |
| | | } |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createBySuccessMsg(String msg,HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(msg,request.getHeader(LANG))); |
| | | } |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(T data) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), data); |
| | | } |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(String data,HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.SUCCESS.getCode(), new GoogleTranslateUtil().translate(data,request.getHeader(LANG))); |
| | | } |
| | | |
| | | public static <T> ServerResponse<T> createBySuccess(String msg, T data) { |
| | |
| | | public static <T> ServerResponse<T> createByErrorMsg(String errormsg) { |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), errormsg); |
| | | } |
| | | public static <T> ServerResponse<T> createByErrorMsg(String errormsg, HttpServletRequest request) { |
| | | return new ServerResponse(ResponseCode.ERROR.getCode(), new GoogleTranslateUtil().translate(errormsg,request.getHeader(LANG))); |
| | | } |
| | | |
| | | |
| | | public static <T> ServerResponse<T> createByErrorCodeMsg(int errorcode, String errormsg) { |
| | | return new ServerResponse(errorcode, errormsg); |