Skip to content

Commit c73aedb

Browse files
committed
💡 限制 sitemap 中的文章条数为 500
1 parent c33cad0 commit c73aedb

File tree

5 files changed

+42
-2
lines changed

5 files changed

+42
-2
lines changed

blog-core/src/main/java/com/zyd/blog/business/service/BizArticleService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,13 @@ public interface BizArticleService extends AbstractService<Article, Long> {
6161
*/
6262
List<Article> listHotArticle(int pageSize);
6363

64+
/**
65+
* 获取 sitemap 中用到的文章列表
66+
*
67+
* @return
68+
*/
69+
List<Article> listOfSitemap(int pageSize);
70+
6471
/**
6572
* 根据某篇文章获取与该文章相关的文章
6673
*

blog-core/src/main/java/com/zyd/blog/business/service/impl/BizArticleServiceImpl.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,20 @@ public List<Article> listHotArticle(int pageSize) {
328328
return list;
329329
}
330330

331+
@Override
332+
public List<Article> listOfSitemap(int pageSize) {
333+
PageHelper.startPage(1, pageSize);
334+
List<BizArticle> entityList = bizArticleMapper.listOfSitemap();
335+
if (CollectionUtils.isEmpty(entityList)) {
336+
return null;
337+
}
338+
List<Article> list = new ArrayList<>();
339+
for (BizArticle entity : entityList) {
340+
list.add(new Article(entity));
341+
}
342+
return list;
343+
}
344+
331345
@Override
332346
@Transactional(rollbackFor = Exception.class)
333347
public Article insert(Article entity) {

blog-core/src/main/java/com/zyd/blog/persistence/mapper/BizArticleMapper.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
import com.zyd.blog.plugin.BaseMapper;
66
import org.apache.ibatis.annotations.Mapper;
77
import org.apache.ibatis.annotations.Param;
8-
import org.springframework.stereotype.Repository;
98

109
import java.util.Date;
1110
import java.util.List;
@@ -59,6 +58,13 @@ public interface BizArticleMapper extends BaseMapper<BizArticle> {
5958
*/
6059
List<BizArticle> listHotArticle();
6160

61+
/**
62+
* 获取 sitemap 中用到的文章列表
63+
*
64+
* @return
65+
*/
66+
List<BizArticle> listOfSitemap();
67+
6268
/**
6369
* 是否存在文章
6470
*

blog-core/src/main/resources/mybatis/BizArticleMapper.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,5 +277,18 @@
277277
</foreach>
278278
)
279279
</update>
280+
281+
<!-- 获取 sitemap 中用到的文章列表 -->
282+
<select id="listOfSitemap" resultMap="rm">
283+
SELECT
284+
a.id,
285+
a.title,
286+
a.create_time,
287+
a.update_time
288+
FROM
289+
biz_article a
290+
ORDER BY
291+
a.update_time DESC
292+
</select>
280293
</mapper>
281294

blog-web/src/main/java/com/zyd/blog/controller/RestWebSiteController.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private String getSitemap(TemplateKeyEnum key) {
6767
Map<String, Object> map = new HashMap<>();
6868
map.put("articleTypeList", typeService.listAll());
6969
map.put("articleTagsList", tagsService.listAll());
70-
map.put("articleList", articleService.listAll());
70+
map.put("articleList", articleService.listOfSitemap(500));
7171
map.put("config", configService.getConfigs());
7272
return FreeMarkerUtil.template2String(template.getRefValue(), map, true);
7373
}

0 commit comments

Comments
 (0)