Skip to content

Conversation

@WuSangui571
Copy link

描述问题(Describe the Bug)

在博客文章详情页中,点击“上一篇”按钮时,跳转的不是当前文章的上一篇,而是整个博客的第一篇文章


复现步骤(To Reproduce)

  1. 打开任意一篇中间位置的文章(比如第三篇)。
  2. 点击页面底部的“上一篇”链接。
  3. 观察跳转后的页面。

期望行为(Expected behavior)
应该跳转到当前文章的上一篇(发布时间或者 id 更小的一篇)。

实际行为(Actual behavior)
跳转到了整个博客的第一篇文章。


问题原因分析(Possible Cause)

getPreArticle 方法中,查询逻辑是:

SELECT ...
FROM ...
WHERE article_id < #{id}
ORDER BY article_id
LIMIT 1

由于 ORDER BY article_id 是升序排列,导致拿到了所有比当前 id 小的文章中最小 id 的那篇,而不是最近的一篇。


建议修复(Suggested Fix)

ORDER BY 语句修改为降序排列:

ORDER BY article_id DESC

这样就能正确取到最近的上一篇文章


补充信息(Additional context)

测试环境:

  • 数据库:MySQL 8.0
  • 浏览器:Chrome 124

感谢作者的辛苦开发!❤️
希望项目越来越好!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant