修复标题为空导致的无法点击查看问题

This commit is contained in:
Novocaine 2021-09-01 18:38:37 +08:00
parent b9a1114c25
commit 2a29da6e82
2 changed files with 5 additions and 8 deletions

View File

@ -2,8 +2,8 @@ DROP TABLE IF EXISTS `discuss_post`;
SET character_set_client = utf8mb4 ; SET character_set_client = utf8mb4 ;
CREATE TABLE `discuss_post` ( CREATE TABLE `discuss_post` (
`id` int(11) NOT NULL AUTO_INCREMENT, `id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL, `user_id` int(11) NOT NULL,
`title` varchar(100) DEFAULT NULL, `title` varchar(100) NOT NULL,
`content` text, `content` text,
`type` int(11) DEFAULT NULL COMMENT '0-普通; 1-置顶;', `type` int(11) DEFAULT NULL COMMENT '0-普通; 1-置顶;',
`status` int(11) DEFAULT NULL COMMENT '0-正常; 1-精华; 2-拉黑;', `status` int(11) DEFAULT NULL COMMENT '0-正常; 1-精华; 2-拉黑;',

View File

@ -13,12 +13,14 @@ import com.greate.community.util.RedisKeyUtil;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.util.HtmlUtils; import org.springframework.web.util.HtmlUtils;
import javax.validation.constraints.NotEmpty;
import java.io.File; import java.io.File;
import java.util.*; import java.util.*;
@ -114,12 +116,7 @@ public class DiscussPostController implements CommunityConstant {
*/ */
@PostMapping("/add") @PostMapping("/add")
@ResponseBody @ResponseBody
public String addDiscussPost(String title, String content) { public String addDiscussPost(@NotEmpty(message = "文章标题不能为空") String title, String content, @AuthenticationPrincipal User user) {
User user = hostHolder.getUser();
if (user == null) {
return CommunityUtil.getJSONString(403, "您还未登录");
}
DiscussPost discussPost = new DiscussPost(); DiscussPost discussPost = new DiscussPost();
discussPost.setUserId(user.getId()); discussPost.setUserId(user.getId());
discussPost.setTitle(title); discussPost.setTitle(title);