首页>代码>ssm整合开发java在线考试系统,通过maven搭建>/examxx/src/main/java/com/extr/controller/CommentController.java
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;

	}

}
最近下载更多
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日
朱俪的邮件及存储  LV8 2023年3月12日
最近浏览更多
三秋桂子  LV1 2024年12月22日
ma406805131  LV19 2024年12月9日
hx0204  LV2 2024年11月1日
3334004690  LV10 2024年6月24日
林守汐  LV2 2024年6月20日
Maple1nk 2024年6月12日
暂无贡献等级
865581316LLL  LV6 2024年6月12日
happySuperman  LV2 2024年6月4日
Strive_  LV2 2024年5月14日
Boss绝  LV9 2024年4月15日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友