Android应用程序框架-004.bean层
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Android应用程序框架-004.bean层,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含2991字,纯文字阅读大概需要5分钟。
内容图文
基于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使用
内容总结
以上是互联网集市为您收集整理的Android应用程序框架-004.bean层全部内容,希望文章能够帮你解决Android应用程序框架-004.bean层所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。