Skip to content

Commit f25ee68

Browse files
committed
优化搜索笔记功能,使用QString::arg方法替代直接字符串拼接,提高代码可读性和维护性。
1 parent 989589d commit f25ee68

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

notedatabase.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,8 @@ QList<Note> NoteDatabase::searchNotes(const QString &keyword)
238238
query.prepare("SELECT id, title, content, create_time, update_time FROM notes "
239239
"WHERE title LIKE ? OR content LIKE ? "
240240
"ORDER BY update_time DESC");
241-
query.addBindValue("%" + keyword + "%");
242-
query.addBindValue("%" + keyword + "%");
241+
query.addBindValue(QString("%%1%").arg(keyword));
242+
query.addBindValue(QString("%%1%").arg(keyword));
243243

244244
if (!query.exec()) {
245245
qDebug() << "搜索笔记失败: " << query.lastError().text();

0 commit comments

Comments
 (0)