zoukankan      html  css  js  c++  java
  • java返回数据工具类

      1 import com.qbskj.project.util.SpringUtils;
      2 
      3 /**
      4  * 消息
      5  * 
      6  */
      7 public class Message {
      8 
      9     /**
     10      * 类型
     11      */
     12     public enum Type {
     13 
     14         /** 成功 */
     15         success,
     16 
     17         /** 警告 */
     18         warn,
     19 
     20         /** 错误 */
     21         error
     22     }
     23 
     24     /** 类型 */
     25     private Type type;
     26 
     27     /** 内容 */
     28     private String content;
     29 
     30     /** 数据 */
     31     private Object data;
     32 
     33     /**
     34      * 初始化一个新创建的 Message 对象,使其表示一个空消息。
     35      */
     36     public Message() {
     37 
     38     }
     39 
     40     /**
     41      * 初始化一个新创建的 Message 对象
     42      * 
     43      * @param type
     44      *            类型
     45      * @param content
     46      *            内容
     47      */
     48     public Message(Type type, String content) {
     49         this.type = type;
     50         this.content = content;
     51     }
     52 
     53     /**
     54      * @param type
     55      *            类型
     56      * @param content
     57      *            内容
     58      * @param args
     59      *            参数
     60      */
     61     public Message(Type type, String content, Object... args) {
     62         this.type = type;
     63         this.content = SpringUtils.getMessage(content, args);
     64     }
     65 
     66     /**
     67      * @param type
     68      *            类型
     69      * @param data
     70      *            数据
     71      * @param content
     72      *            内容
     73      * @param args
     74      *            参数
     75      */
     76     public Message(Type type, Object data, String content, Object... args) {
     77         this.type = type;
     78         this.data = data;
     79         this.content = SpringUtils.getMessage(content, args);
     80     }
     81 
     82     /**
     83      * 返回成功消息
     84      * 
     85      * @param content
     86      *            内容
     87      * @param args
     88      *            参数
     89      * @return 成功消息
     90      */
     91     public static Message success(String content, Object... args) {
     92         return new Message(Type.success, content, args);
     93     }
     94 
     95     /**
     96      * 返回成功消息
     97      * 
     98      * @param content
     99      *            内容
    100      * @param args
    101      *            参数
    102      * @return 成功消息
    103      */
    104     public static Message successData(Object data, String content, Object... args) {
    105         return new Message(Type.success, data, content, args);
    106     }
    107 
    108     /**
    109      * 返回警告消息
    110      * 
    111      * @param content
    112      *            内容
    113      * @param args
    114      *            参数
    115      * @return 警告消息
    116      */
    117     public static Message warn(String content, Object... args) {
    118         return new Message(Type.warn, content, args);
    119     }
    120 
    121     /**
    122      * 返回错误消息
    123      * 
    124      * @param content
    125      *            内容
    126      * @param args
    127      *            参数
    128      * @return 错误消息
    129      */
    130     public static Message error(String content, Object... args) {
    131         return new Message(Type.error, content, args);
    132     }
    133 
    134     /**
    135      * 获取类型
    136      * 
    137      * @return 类型
    138      */
    139     public Type getType() {
    140         return type;
    141     }
    142 
    143     /**
    144      * 设置类型
    145      * 
    146      * @param type
    147      *            类型
    148      */
    149     public void setType(Type type) {
    150         this.type = type;
    151     }
    152 
    153     /**
    154      * 获取内容
    155      * 
    156      * @return 内容
    157      */
    158     public String getContent() {
    159         return content;
    160     }
    161 
    162     /**
    163      * 设置内容
    164      * 
    165      * @param content
    166      *            内容
    167      */
    168     public void setContent(String content) {
    169         this.content = content;
    170     }
    171 
    172     /**
    173      * @return the data
    174      */
    175     public Object getData() {
    176         return data;
    177     }
    178 
    179     /**
    180      * @param data
    181      *            the data to set
    182      */
    183     public void setData(Object data) {
    184         this.data = data;
    185     }
    186 
    187     @Override
    188     public String toString() {
    189         return "Message [type=" + type + ", content=" + SpringUtils.getMessage(content) + "]";
    190     }
    191 
    192 }
    成功不是终点,失败也并非末日,重要的是前行的勇气!
  • 相关阅读:
    正则表达式
    HashTable与HashMap的区别
    求解连续子数组乘积的最大值
    求解N个值中最大的k个数,N远大于k
    C++权限修饰符
    DBSCAN算法
    【leetcode】1318. Minimum Flips to Make a OR b Equal to c
     【leetcode】1317. Convert Integer to the Sum of Two No-Zero Integers
    【leetcode】1316. Distinct Echo Substrings
    【leetcode】1315. Sum of Nodes with Even-Valued Grandparent
  • 原文地址:https://www.cnblogs.com/DSH-/p/10791162.html
Copyright © 2011-2022 走看看