使用GreenDao數據庫的記錄

1.List<T>自定義數據的增加方法:

寫一個convert轉化器,然後用FastJson的格式轉化方法來處理轉化問題

例如:

數據庫的一個自定義List,叫priceArray.

然後就進行轉化:

public static class PriceArrayBeanConvert implements PropertyConverter<List<PriceArrayBean>, String> {

        @Override
        public List<PriceArrayBean> convertToEntityProperty(String databaseValue) {//從數據庫讀取
            List<PriceArrayBean> priceArrayBeans = JSON.parseArray(databaseValue, PriceArrayBean.class);
            return priceArrayBeans;
        }

        @Override
        public String convertToDatabaseValue(List<PriceArrayBean> entityProperty) {//存儲到數據庫
            return JSON.toJSONString(entityProperty);
        }
    }

FastJson的依賴包:

//fast json
    implementation "com.alibaba:fastjson:$fastJsonAndroidVersion"
    implementation "com.alibaba:fastjson:$fastJsonVersion"

    fastJsonVersion = "1.2.55"
    fastJsonAndroidVersion = "1.1.70.android"

其他關於greendao的數據庫操作就很簡單了

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章