惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

www.infosecurity-magazine.com
www.infosecurity-magazine.com
Security Archives - TechRepublic
Security Archives - TechRepublic
TaoSecurity Blog
TaoSecurity Blog
Cloudbric
Cloudbric
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
N
News and Events Feed by Topic
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
S
Securelist
The Cloudflare Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
D
DataBreaches.Net
S
Schneier on Security
L
LangChain Blog
Jina AI
Jina AI
M
MIT News - Artificial intelligence
Recent Announcements
Recent Announcements
T
Tenable Blog
B
Blog RSS Feed
V
Visual Studio Blog
Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
T
The Exploit Database - CXSecurity.com
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
WordPress大学
WordPress大学
W
WeLiveSecurity
I
InfoQ
The Hacker News
The Hacker News
雷峰网
雷峰网
月光博客
月光博客
P
Privacy & Cybersecurity Law Blog
O
OpenAI News
Hacker News: Ask HN
Hacker News: Ask HN
T
Threat Research - Cisco Blogs
GbyAI
GbyAI
The Last Watchdog
The Last Watchdog
P
Privacy International News Feed
Cyberwarzone
Cyberwarzone
S
SegmentFault 最新的问题
L
Lohrmann on Cybersecurity
人人都是产品经理
人人都是产品经理
V
V2EX
V
Vulnerabilities – Threatpost
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
C
Cybersecurity and Infrastructure Security Agency CISA
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
T
Troy Hunt's Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
阮一峰的网络日志
阮一峰的网络日志
SecWiki News
SecWiki News
Microsoft Azure Blog
Microsoft Azure Blog

MoonLab

VSCode + OpenOCD 远程调试开发STM32 Clangd + VSCode使用方法 Keil5 编译错误 error: call to undeclared function '__enable_irq' BTSNOOP is FUN! 算法 - 前缀和 2025蓝桥杯赛后总结 三星ZFold 3改造 JavaScript 逆向 Steam 登录二维码 快速求解平方根倒数算法 Protobuf Android设备安装Debian成为BT下载服务器 [双系统] Windows 更新摧毁了我的Linux系统 Reading List Golang embed 使用问题 Hexo博客自动备份插件 云盘备份支持 通过汇编分析栈、函数调用 esp&ebp Git push 出现 permisson denied error 403 Android Shizuku源码分析 第二篇 Android Shizuku源码分析 Android 监听第三方Activity的一举一动 Android笔记#1 View的事件分发机制解析 知乎日报的问题 使用Hexo Hello World Ubnutu 无法启动网易云音乐 - 总结 Windows 好软推荐 | 这一定是良心软件 typecho - http转https 如何评价Android P MoonLab MoonLab MoonLab 关于 项目
坑:Litepal save方法返回true却没有保存
LingC · 2020-02-24 · via MoonLab

在开发 Madoka 日记时,做到导出导入的功能时,我想偷个懒导出直接用 Gson 将 Java 对象转换为 json 然后放在 txt 中,导入的时候再将 json 转为 javaBean 就行啦。

而数据库我用的是 Litepal 直接搞,使用这个库的好处就是速度快,方便,适合新手。

但其实 sqlite 的语法和一些其他的语句并不难,所以用这个库就是为了方便…

使用 Litepal 储存数据时,需要调用 save() 方法。

这里我就遇到了一个问题,明明 save() 方法返回的是 true ,但数据库里没有需要保存的数据啊?

    Gson gson = new Gson();
    Diary diary = gson.fromJson(json, Diary.class);
    return diary.save();

这是调用 Gson 将 json 转换为 javabean 对象。

明明 Diary 的内容全是正确的,我开始询问度娘。

结果没找到跟我的问题直接相关的文章,结果我看到了有个人在吐槽啥 setting getting,我就想到了会不会是因为没有调用 Diary 的构造方法?

Diary 作为一个 Litepal 的,它是继承自 LitePalSupport 的,会不会是因为没有调用 LitePalSupport 的构造方法呢?

我将导入代码改了一下:

        Gson gson = new Gson();
        Diary diary = gson.fromJson(json, Diary.class);
        Diary saveDiary = new Diary();
        saveDiary.setId(diary.getId());
        saveDiary.setCreatedTime(diary.getCreatedTime());
        saveDiary.setLastUpdatedTime(diary.getLastUpdatedTime());
        ... 省略一万个代码
        return saveDiary.save();

果然,最后正常了…

(水文真开心)

咕咕咕