All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cn.flood.cloud.gateway.result.ResultWapper Maven / Gradle / Ivy

There is a newer version: 2.7.14.0
Show newest version
/**  
* 

Title: ResultWapper.java

*

Description:

*

Copyright: Copyright (c) 2018

* @author mmdai * @date 2018年12月6日 * @version 1.0 */ package cn.flood.cloud.gateway.result; import org.apache.commons.lang3.StringUtils; /** *

Title: ResultWapper

*

Description: 封装返回值

* @author mmdai * @date 2018年12月6日 */ public class ResultWapper { /** * Instantiates a new result mapper. */ private ResultWapper() { } /** * Result. * * @param the element type * @param code the code * @param msg the msg * @param o the o * * @return the wrapper */ public static Result wrap(String code, String msg, E o) { return new Result<>(code, msg, o); } /** * Result. * * @param the element type * @param code the code * @param msg the msg * * @return the wrapper */ public static Result wrap(String code, String msg) { return wrap(code, msg, null); } /** * Result. * * @param the element type * @param code the code * * @return the wrapper */ public static Result wrap(String code) { return wrap(code, null); } /** * Wrap. * * @param the element type * @param e the e * * @return the wrapper */ public static Result wrap(Exception e) { return new Result<>(Result.ERROR_CODE, e.getMessage()); } /** * Un wrapper. * * @param the element type * @param wrapper the wrapper * * @return the e */ public static E unWrap(Result wrapper) { return wrapper.get_data(); } /** * Wrap ERROR. code=500 * * @param the element type * * @return the wrapper */ public static Result error() { return wrap(Result.ERROR_CODE, Result.ERROR_MESSAGE); } /** * Result wrapper. * * @param the type parameter * @param msg the msg * * @return the wrapper */ public static Result error(String msg) { return wrap(Result.ERROR_CODE, StringUtils.isBlank(msg) ? Result.ERROR_MESSAGE : msg); } /** * Wrap SUCCESS. code=200 * * @param the element type * * @return the wrapper */ public static Result ok() { return new Result<>(); } /** * Ok wrapper. * * @param the type parameter * @param o the o * * @return the wrapper */ public static Result ok(E o) { return new Result<>(Result.SUCCESS_CODE, Result.SUCCESS_MSG, o); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy