zoukankan      html  css  js  c++  java
  • [Android] Android GreenDao 保存 JavaBean 或者List <JavaBean>类型数据

    Android GreenDao 保存 JavaBean 或者List <JavaBean>类型数据

    简介

    数据库存储数据基本上每个APP都有用到,GreenDAO 是一个将对象映射到 SQLite 数据库中的轻量且快速的 ORM 解决方案,至于用法这里不再多少,网上有很资料,这里主要说一下,利用GreenDao保存JavaBean类型或者List类型的数据。

    举个栗子

    {
         rating: {
         max: 10,
         average: 7.9,
         stars: "40",
         min: 0
         },
         genres: [
         "动作",
         "奇幻",
         "冒险"
         ],
         title: "海王",
         casts: [
         {
         alt: "https://movie.douban.com/celebrity/1022614/",
         avatars: {
         small: "http://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p32853.webp",
         large: "http://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p32853.webp",
         medium: "http://img1.doubanio.com/view/celebrity/s_ratio_celebrity/public/p32853.webp"
         },
         name: "杰森·莫玛",
         id: "1022614"
         },
         {
         alt: "https://movie.douban.com/celebrity/1044702/",
         avatars: {
         small: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p34697.webp",
         large: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p34697.webp",
         medium: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p34697.webp"
         },
         name: "艾梅柏·希尔德",
         id: "1044702"
         },
         {
         alt: "https://movie.douban.com/celebrity/1010539/",
         avatars: {
         small: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p9206.webp",
         large: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p9206.webp",
         medium: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p9206.webp"
         },
         name: "威廉·达福",
         id: "1010539"
         }
         ],
         collect_count: 397576,
         original_title: "Aquaman",
         subtype: "movie",
         directors: [
         {
         alt: "https://movie.douban.com/celebrity/1032122/",
         avatars: {
         small: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1509950363.8.webp",
         large: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1509950363.8.webp",
         medium: "http://img3.doubanio.com/view/celebrity/s_ratio_celebrity/public/p1509950363.8.webp"
         },
         name: "温子仁",
         id: "1032122"
         }
         ],
         year: "2018",
         images: {
         small: "http://img3.doubanio.com/view/photo/s_ratio_poster/public/p2541280047.webp",
         large: "http://img3.doubanio.com/view/photo/s_ratio_poster/public/p2541280047.webp",
         medium: "http://img3.doubanio.com/view/photo/s_ratio_poster/public/p2541280047.webp"
         },
         alt: "https://movie.douban.com/subject/3878007/",
         id: "3878007"
         }

    上面是豆瓣电影一个电影详情的数据,一般复杂,有一些套嵌JsonObject和JsonArray,数据库存储的都是基本类型,像上面那些objec或者array类型又改如何存到数据库中,这是个问题。GreenDao为我们提了一个解决方案,就是把这些数据统一都转成String类型,存到数据库中,用的时候再转成相应的类型。

    具体分析

    这里分别列数两个例子,一个是JsonObject, 一个是JsonArray的。
    首先第一个字段rating,电影的评分,返回的是一个JsonObject,写出它的JavaBean

    本文参考:

    https://www.jianshu.com/p/9b817a62eb22

    https://blog.csdn.net/zxm317122667/article/details/73528387

    https://www.jianshu.com/p/5d6de7cda713

    本博客地址: wukong1688

    本文原文地址:https://www.cnblogs.com/wukong1688/p/10748077.html

    转载请著名出处!谢谢~~

  • 相关阅读:
    apache启用gzip压缩方法--转载自http://www.cnblogs.com/linzhenjie/archive/2013/03/05/2943635.html
    yii 主从数据库分离-转载http://www.yiichina.com/doc/guide/2.0/db-dao
    服装尺寸
    php 同步因子的并发处理
    NFC会员管理-转载自http://technews.cn/2014/09/13/nfc-sticker/
    Redis 利用锁机制来防止缓存过期产生的惊群现象-转载自 http://my.oschina.net/u/1156660/blog/360552
    移动端H5页面的设计稿尺寸大小规范-转载自http://www.chinaz.com/design/2015/1103/465670.shtml
    服饰行业淘宝商城店铺首页设计报告-转载自http://bbs.paidai.com/topic/88363
    网页设计的标准尺寸
    hdu2099
  • 原文地址:https://www.cnblogs.com/wukong1688/p/10748077.html
Copyright © 2011-2022 走看看