Android应用程序框架-004.bean层

Android应用程序框架-004.bean层,第1张

概述基于Gson上,搭建bean层 上码:1/**2*@author黄宗旭3*@version20.08.274*/5publicinterfaceIJson{6/**7*从json进行转换8*@paramjsonjson串,非空9*@return转换成功标记10*/11booleanfromJson(String

基于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      * 对象转为Json15      * @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     @OverrIDe10     public boolean fromJson(String Json) {11         return false;12     }13 14     @OverrIDe15     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 code42      */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 msg55      */56     public String getErrorMsg() {57         return errorMsg;58     }59 60     /**61      * Sets error msg.62      *63      * @param errorMsg the error msg64      */65     public voID setErrorMsg(String errorMsg) {66         this.errorMsg = errorMsg;67     }68 69     /**70      * Gets data.71      *72      * @return the data73      */74     public Object getData() {75         return data;76     }77 78     /**79      * Sets data.80      *81      * @param data the data82      */83     public voID setData(Object data) {84         this.data = data;85     }86 87     @OverrIDe88     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使用

 

总结

以上是内存溢出为你收集整理的Android应用程序框架-004.bean层全部内容,希望文章能够帮你解决Android应用程序框架-004.bean层所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://www.54852.com/web/1060017.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-25
下一篇2022-05-25

发表评论

登录后才能评论

评论列表(0条)

    保存