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);
        }
    
    }
  • 相关阅读:
    es6字符串扩展(+模板字符串拼接)
    MySQL-技术专区-mysql数据库权限管理
    MySQL-技术专区-数据库权限管理
    开源软件的盈利模式
    分布式-技术专区-Redis分布式锁实现-第二步
    分布式-技术专区-Redis分布式锁实现-第一步
    分布式-技术专区-Redis分布式锁原理实现
    JPA接口整理归纳方法规则
    备份整理-实用归纳
    Zookeeper-技术专区-运作流程分析介绍
  • 原文地址:https://www.cnblogs.com/chong-zuo3322/p/12855298.html
Copyright © 2011-2022 走看看