首页>代码>spring+spring mvc+mybatis+ajax+jquery实现简单的问答系统>/problem/src/com/hfxt/web/ProblemContorller.java
package com.hfxt.web; import java.util.HashMap; import java.util.List; import java.util.Map; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.ModelAndView; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.hfxt.biz.AnswersBiz; import com.hfxt.biz.QuestionsBiz; import com.hfxt.entity.Answers; import com.hfxt.entity.Questions; import com.hfxt.tool.Pager; @Controller public class ProblemContorller { @Autowired private QuestionsBiz qBiz; @Autowired private AnswersBiz aBiz; @RequestMapping(value="pagerindex.html") public ModelAndView pagerindex(Model model,Pager<Questions> pager,Questions questions) { int count=qBiz.getCount(); pager.setTotal(count); List<Questions> qList=qBiz.getPagerQuestions(questions,(pager.getCurrentPage()-1)*pager.getPageSize(), pager.getPageSize()); for (Questions questions2:qList) { int ansCount=aBiz.getAnsCountByQid(questions2.getId()); questions2.setAnswerCount(ansCount); } pager.setPageRecords(qList); model.addAttribute("pager", pager); model.addAttribute("q", questions); ModelAndView view=new ModelAndView("index"); return view; } @RequestMapping(value="getQuestionsById.html") public ModelAndView getQuestionsById(Model model,Integer id) { Questions questions=qBiz.getQuestionsById(id); List<Answers> aList=aBiz.getAnswersByQid(id); model.addAttribute("aList",aList); model.addAttribute("q", questions); ModelAndView view=new ModelAndView("addAnswers"); return view; } @RequestMapping(value="toaddQuestion.html") public ModelAndView toaddQuestion(Model model) { ModelAndView view=new ModelAndView("addQuestion"); return view; } @RequestMapping(value="addQuestions") @ResponseBody public Map<String,Object> addQuestions(Model model,Questions questions){ Map<String,Object> map=new HashMap<String, Object>(); int result=qBiz.addQuestions(questions); if (result==1) { map.put("recode",true); map.put("remsg","提问成功"); }else{ map.put("recode", false); map.put("remsg", "提问失败"); } return map; } @RequestMapping(value="addAnswers") @ResponseBody public Map<String, Object> addAnswers(Model model,Answers answers) { int result=aBiz.addAnswers(answers); Map<String,Object> map=new HashMap<String, Object>(); if (result==1) { map.put("recode",true); map.put("remsg","回答成功"); }else{ map.put("recode", false); map.put("remsg", "回答失败"); } return map; } }
最近下载更多
xmx123 LV5
2023年8月22日
6389181 LV7
2023年6月1日
lbsers LV5
2023年5月31日
ssh123 LV10
2023年4月18日
微信网友_6409795458142208 LV1
2023年3月29日
李亮 LV19
2023年3月5日
zzzzzz1255 LV1
2022年12月16日
001128wxw LV3
2022年12月15日
renyuan LV9
2022年12月11日
zxc131313 LV12
2022年12月9日
最近浏览更多
yxzzxy LV3
2月18日
1222222222222222222 LV2
2023年12月17日
帅涵123456 LV2
2023年11月6日
随手一个用户名 LV1
2023年10月13日
微信网友_6681934323765248
2023年10月7日
暂无贡献等级
wspcyhy LV1
2023年9月26日
小妹妹 LV7
2023年9月20日
shuangfu LV24
2023年9月12日
xmx123 LV5
2023年8月22日
uni-code_0123 LV1
2023年8月4日