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的数据库操作就很简单了
本文介绍如何利用FastJson实现自定义List数据类型的转换,包括从数据库读取和存储到数据库的过程。通过创建PriceArrayBeanConvert类,实现了List<PriceArrayBean>与String之间的相互转换。
1173

被折叠的 条评论
为什么被折叠?



