fix null content handling in user posts

This commit is contained in:
Tim
2025-07-10 00:11:13 +08:00
parent 3dbb1c26bb
commit 6351f329cd

View File

@@ -175,11 +175,14 @@ public class UserController {
PostMetaDto dto = new PostMetaDto();
dto.setId(post.getId());
dto.setTitle(post.getTitle());
String content = post.getContent();
if (content == null) {
content = "";
}
if (snippetLength >= 0) {
String c = post.getContent();
dto.setSnippet(c.length() > snippetLength ? c.substring(0, snippetLength) : c);
dto.setSnippet(content.length() > snippetLength ? content.substring(0, snippetLength) : content);
} else {
dto.setSnippet(post.getContent());
dto.setSnippet(content);
}
dto.setCreatedAt(post.getCreatedAt());
dto.setCategory(post.getCategory().getName());