============= 后端_阅读更新 ============= /ysdblog-api/src/main/java/com/weihome/ysdblog/service/impl/ArticleServiceImpl.java: ... public class ArticleServiceImpl implements ArticleService { ... @Override public Result details(Long articleId) { ... // 每次显示文章详情,文章阅读数加一 updateArticleViewCount(articleMapper, article.getId(), article.getViewCount()); ... } ... private void updateArticleViewCount( ArticleMapper articleMapper, long id, int viewCount) { Article article = new Article(); article.setViewCount(viewCount + 1); LambdaUpdateWrapper
updateWrapper = new LambdaUpdateWrapper<>(); updateWrapper.eq(Article::getId, id); updateWrapper.eq(Article::getViewCount, viewCount); // 只更新非空属性对应的字段 articleMapper.update(article, updateWrapper); } ... }