首页>代码>基于SSM开发的社区论坛系统>/Genesis-master/src/main/java/com/withstars/controller/ReplyController.java
package com.withstars.controller;

import com.withstars.domain.Reply;
import com.withstars.service.impl.ReplyServiceImpl;
import com.withstars.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.UnsupportedEncodingException;
import java.util.Date;

/**
 * 回复相关控制类
 */
@Controller
public class ReplyController {

    @Autowired
    public ReplyServiceImpl replyService;
    @Autowired
    public UserServiceImpl userService;

    /**
     * 添加评论
     */
    @RequestMapping(value = "/reply/add",method = RequestMethod.POST)
    public ModelAndView addReply(HttpServletRequest request, HttpSession session){

        try {
            request.setCharacterEncoding("utf-8");
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }
        //处理参数
        Integer topicId=Integer.parseInt(request.getParameter("topicId"));
        Integer replyUserId=Integer.parseInt(request.getParameter("replyUserId"));
        String content=request.getParameter("content");
        //创建reply
        Reply reply=new Reply();
        reply.setTopicId(topicId);
        reply.setReplyUserId(replyUserId);
        reply.setContent(content);
        reply.setCreateTime(new Date());
        reply.setUpdateTime(new Date());
        //执行添加
        boolean ifSucc=replyService.addReply(reply);
        //添加积分
        boolean ifSuccAddCredit=userService.addCredit(1,replyUserId);

        //新建视图
        ModelAndView view=new ModelAndView("redirect:/t/"+topicId);
        return view;
    }


}
最近下载更多
ma406805131  LV19 2024年12月18日
bankroll  LV5 2024年12月17日
zolscy  LV24 2024年11月26日
krispeng  LV14 2024年11月14日
799743530  LV11 2024年7月10日
2636804923  LV6 2024年6月17日
xiaoxia1012  LV1 2024年6月12日
cccl112  LV1 2024年6月5日
zzcio123  LV1 2024年5月27日
2131234536546  LV7 2024年3月31日
最近浏览更多
2072376767  LV2 2024年12月26日
三秋桂子  LV1 2024年12月22日
taoshen95  LV16 2024年12月21日
ma406805131  LV19 2024年12月18日
bankroll  LV5 2024年12月16日
微信网友_15002431817 2024年12月16日
暂无贡献等级
按市场洒出C  LV1 2024年12月8日
krispeng  LV14 2024年11月14日
shunlun8855  LV1 2024年10月29日
wlax99  LV12 2024年10月12日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友