zoukankan      html  css  js  c++  java
  • java工具类5-Result,pageResult

    Result:

    import java.util.HashMap;
    import java.util.Map;
    
    import com.door.common.constant.IErrorCode;
    
    /**
     * 
     * 结果类 date: 2018年1月17日 上午9:52:08
     * 
     * @author why
     * @version @param <T>
     * @since JDK 1.7
     * @see
     */
    public class Result<T> {
        public static final String SUCCESS = "0";
        public static final String SCUCESS_MSG = "success";
    
        private String result = SUCCESS;
        private String msg = SCUCESS_MSG;
        private T data;
        private Map<String, Object> header = new HashMap<>();
    
        public Result() {}
    
        public Result(IErrorCode error, Object... msgParams) {
            this.setError(error, msgParams);
        }
    
        public Result(IErrorCode error) {
            this.setError(error);
        }
    
        public void setError(IErrorCode error, Object... msgParams) {
            this.result = error.getCode();
            this.msg = error.getMsg();
            if (msgParams != null && msgParams.length > 0) {
                this.msg = String.format(msg, msgParams);
            }
        }
    
        public void setError(IErrorCode error) {
            this.setError(error, new Object[] {});
        }
    
        public String getResult() {
            return result;
        }
    
        public void setResult(String result) {
            this.result = result;
        }
    
        public String getMsg() {
            return msg;
        }
    
        public void setMsg(String msg) {
            this.msg = msg;
        }
    
        public T getData() {
            return data;
        }
    
        public void setData(T data) {
            this.data = data;
        }
    
        public boolean isSuccess() {
            return SUCCESS.equals(result);
        }
    
        public void addHeader(String key, String value) {
            header.put(key, value);
        }
    
        public Map<String, Object> getHeader() {
            return header;
        }
    
        public void setHeader(Map<String, Object> header) {
            this.header = header;
        }
    
        @Override
        public String toString() {
            return "Result [result=" + result + ", msg=" + msg + ", data=" + data + "]";
        }
    
    }

    PageResult:

    import java.util.ArrayList;
    import java.util.List;
    
    import com.door.common.constant.IErrorCode;
    
    
    /**
     * 
     * 分页result date: 2018年1月17日 上午9:51:50
     * 
     * @author why
     * @version @param <T>
     * @since JDK 1.7
     * @see
     */
    public class PageResult<T> {
        public static final String SUCCESS = "0";
        public static final String SCUCESS_MSG = "success";
    
        private String result = SUCCESS;
        private String msg = SCUCESS_MSG;
        private Long total = 0L;
        private List<T> rows = new ArrayList<>();
    
        public PageResult() {}
    
        public PageResult(IErrorCode error, Object... msgParams) {
            this.setError(error, msgParams);
        }
    
        public PageResult(IErrorCode error) {
            this.setError(error);
        }
    
        public String getResult() {
            return result;
        }
    
        public void setResult(String result) {
            this.result = result;
        }
    
        public String getMsg() {
            return msg;
        }
    
        public void setMsg(String msg) {
            this.msg = msg;
        }
    
        public Long getTotal() {
            return total;
        }
    
        public void setTotal(Long total) {
            this.total = total;
        }
    
        public List<T> getRows() {
            return rows;
        }
    
        public void setRows(List<T> rows) {
            this.rows = rows;
        }
    
        public void setError(IErrorCode error, Object... msgParams) {
            this.result = error.getCode();
            this.msg = error.getMsg();
            if (msgParams != null && msgParams.length > 0) {
                this.msg = String.format(msg, msgParams);
            }
        }
    
        public void setError(IErrorCode error) {
            this.setError(error, new Object[] {});
        }
    
        public boolean isSuccess() {
            return SUCCESS.equals(result);
        }
    
    }
  • 相关阅读:
    Linux Shell 文本处理工具集锦--Awk―sed―cut(row-based, column-based),find、grep、xargs、sort、uniq、tr、cut、paste、wc
    ACME[free https] Linux中使用curl命令访问https站点4种常见错误和解决方法
    php composer,update-ca-trust
    bootloader,kernel,initrc
    linux devcie lspci,lscpu,blkdiscard,fstrim,parted,partprobe,smartctl
    剖析Docker文件系统:Aufs与Devicemapper
    Linux 内核中的 Device Mapper 机制
    MapReduce报错:Error: java.io.IOException: Initialization of all the collectors failed. Error in last collector was :interface javax.xml.soap.Text
    hadoop运行报错Wrong FS: hdfs:/, expected: file:///
    Hadoop 伪分布式上安装 Hive
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/12855298.html
Copyright © 2011-2022 走看看