zoukankan      html  css  js  c++  java
  • Apk应用框架Collie-004.bean层

    基于Gson上,搭建bean层

    上码:

     1 /**
     2  * @author 黄宗旭
     3  * @version 20.08.27
     4  */
     5 public interface IJson {
     6     /**
     7      * 从json进行转换
     8      * @param json json串 ,非空
     9      * @return 转换成功标记
    10      */
    11     boolean fromJson(String json);
    12 
    13     /**
    14      * 对象转为json
    15      * @return json串
    16      */
    17     String toJson();
    18 }
     1 /**
     2  * 基础bean类
     3  *
     4  * @author 黄宗旭
     5  * @version 20.08.27
     6  */
     7 public class BaseBean implements IJson {
     8 
     9     @Override
    10     public boolean fromJson(String json) {
    11         return false;
    12     }
    13 
    14     @Override
    15     public String toJson() {
    16         return GsonHelper.getInstance().toJson(this);
    17     }
    18 }

    这里可见GsonHelper的使用地方

    另外再贴:

     1 /**
     2  * 响应结果结构
     3  *
     4  * @author 黄宗旭
     5  * @version 20.08.27
     6  */
     7 public class ResponseResult extends BaseBean {
     8     @SerializedName("ErrorCode")
     9     private Integer errorCode;
    10     @SerializedName("ErrorMsg")
    11     private String errorMsg;
    12     @SerializedName("Data")
    13     private Object data;
    14 
    15     /**
    16      * Instantiates a new Response result.
    17      */
    18     public ResponseResult() {
    19         this.errorCode = 0;
    20         this.errorMsg = "";
    21         this.data = null;
    22     }
    23 
    24     /**
    25      * 拷贝函数
    26      *
    27      * @param source 数据源
    28      */
    29     public void copy(ResponseResult source) {
    30         if (source != null) {
    31             this.errorCode = source.errorCode;
    32             this.errorMsg = source.errorMsg;
    33             this.data = source.data;
    34         }
    35     }
    36 
    37 
    38     /**
    39      * Gets error code.
    40      *
    41      * @return the error code
    42      */
    43     public Integer getErrorCode() {
    44         return errorCode;
    45     }
    46 
    47     public void setErrorCode(Integer errorCode) {
    48         this.errorCode = errorCode;
    49     }
    50 
    51     /**
    52      * Gets error msg.
    53      *
    54      * @return the error msg
    55      */
    56     public String getErrorMsg() {
    57         return errorMsg;
    58     }
    59 
    60     /**
    61      * Sets error msg.
    62      *
    63      * @param errorMsg the error msg
    64      */
    65     public void setErrorMsg(String errorMsg) {
    66         this.errorMsg = errorMsg;
    67     }
    68 
    69     /**
    70      * Gets data.
    71      *
    72      * @return the data
    73      */
    74     public Object getData() {
    75         return data;
    76     }
    77 
    78     /**
    79      * Sets data.
    80      *
    81      * @param data the data
    82      */
    83     public void setData(Object data) {
    84         this.data = data;
    85     }
    86 
    87     @Override
    88     public boolean fromJson(String json) {
    89         boolean isSuccess = false;
    90         if (json != null && json.length() > 0) {
    91             ResponseResult bean = GsonHelper.getInstance().fromJson(json, ResponseResult.class);
    92             copy(bean);
    93             isSuccess = true;
    94         }
    95 
    96         return isSuccess;
    97     }
    98 }

    bean的使用就不多说了吧,bean肯定还有不断补充,也是被db或biz或ui使用

  • 相关阅读:
    关于mysql主从架构master宕机
    恢复drop后的表空间
    rman 恢复drop 表空间模拟恢复
    backup controlfile 和create standby controlfile
    catalog
    rman恢复表(不完全恢复)--需要关闭数据库
    rman备份恢复
    oracle DG 启动和关闭顺序
    ASM-本地数据拷贝
    图解Java设计模式之模板模式
  • 原文地址:https://www.cnblogs.com/GoGoagg/p/13572877.html
Copyright © 2011-2022 走看看