package com.extr.controller; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.security.core.context.SecurityContextHolder; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; import com.extr.controller.domain.Message; import com.extr.domain.question.Comment; import com.extr.domain.question.Comments; import com.extr.security.UserInfo; import com.extr.service.CommentService; import com.extr.util.Page; @Controller public class CommentController { @Autowired private CommentService commentService; @RequestMapping(value = "student/comment-list/{questionId}/{index}/{indexId}", method = RequestMethod.GET) public @ResponseBody Message getQuestionComments(@PathVariable("questionId") int questionId, @PathVariable("index") int index, @PathVariable("indexId") int indexId) { if (index <= 0) index = 1; Message msg = new Message(); msg.setMessageInfo("not-has-next"); Page<Comment> page = new Page<Comment>(); if(index == 1){ page.setPageNo(index); page.setPageSize(6); }else{ index = index + 2; page.setPageNo(index); page.setPageSize(2); } try { List<Comment> commentList = commentService.getCommentByQuestionId(questionId, indexId, page); Comments c = new Comments(); c.setComments(commentList); c.setSize(page.getTotalRecord()); if (page.getTotalRecord() > page.getPageSize() * index) msg.setMessageInfo("has-next"); msg.setObject(c); } catch (Exception e) { msg.setResult(e.getClass().getName()); e.printStackTrace(); } return msg; } @RequestMapping(value = "student/submit-comment", method = RequestMethod.POST) public @ResponseBody Message submitComment(@RequestBody Comment comment, HttpServletRequest request) { Message msg = new Message(); UserInfo userInfo = (UserInfo) SecurityContextHolder.getContext().getAuthentication().getPrincipal(); try { comment.setUserId(userInfo.getUserid()); commentService.addComment(comment); } catch (Exception e) { e.printStackTrace(); msg.setResult(e.getClass().getName()); } return msg; } }

C544350851 LV26
5月27日
865581316LLL LV6
2024年6月12日
pokerf LV5
2024年4月7日
1690356080 LV38
2024年4月5日
shuangfu LV25
2023年12月2日
tmf852 LV5
2023年11月21日
a867609090 LV8
2023年8月29日
qq2901732871 LV9
2023年5月7日
做你的景天 LV7
2023年3月29日
蹇金金 LV7
2023年3月14日

C544350851 LV26
5月27日
songyan
5月26日
暂无贡献等级
348835269 LV11
5月6日
348835269 LV11
5月6日
三秋桂子 LV1
2024年12月22日
ma406805131 LV19
2024年12月9日
hx0204 LV2
2024年11月1日
3334004690 LV11
2024年6月24日
林守汐 LV2
2024年6月20日
Maple1nk
2024年6月12日
暂无贡献等级