AnswerController.java package cn.tedu.ems.controller;import java.util.ArrayList;import java.util.List;import java.util.UUID;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Controller;impor
package cn.tedu.ems.controller; import java.util.ArrayList; import java.util.List; import java.util.UUID; 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.RequestParam; import cn.tedu.ems.pojo.Answer; import cn.tedu.ems.pojo.AnswerEntity; import cn.tedu.ems.pojo.EQ; import cn.tedu.ems.pojo.Result; import cn.tedu.ems.pojo.Test; import cn.tedu.ems.pojo.TestInfo; import cn.tedu.ems.pojo.User; import cn.tedu.ems.service.AnswerService; import cn.tedu.ems.service.EQuestionService; import cn.tedu.ems.service.MultiSelectService; import cn.tedu.ems.service.ScoresService; import cn.tedu.ems.service.SinleselectService; import cn.tedu.ems.service.TestInfoService; import cn.tedu.ems.service.TestService; import cn.tedu.ems.service.UserService; @Controller public class AnswerController extends BaseController{ @Autowired private TestService testService; @Autowired private UserService userService; @Autowired private TestInfoService testInfoService; @Autowired private MultiSelectService multiSelectService; @Autowired private SinleselectService sinleselectService; @Autowired private EQuestionService eQuestionService; @Autowired private ScoresService scoresService; @Autowired private AnswerService answerService; @RequestMapping("/answer") public String answer(@RequestParam(required=false)String testId,Model model){ ListtestInfos=testInfoService.findByTestId(testId); // 获取时间 String time=testService.findTime(testId); List infos=new ArrayList (); for (TestInfo testInfo : testInfos) { if(testInfo.getType()==1){ infos.add(sinleselectService.findByMID(testInfo.getTitleid())); infos.get(infos.size()-1).setType(1); infos.get(infos.size()-1).setMark(testInfo.getMark()); infos.get(infos.size()-1).setTestInfoId(testInfo.getId()); }else if(testInfo.getType()==2){ infos.add(multiSelectService.findByMID(testInfo.getTitleid())); infos.get(infos.size()-1).setType(2); infos.get(infos.size()-1).setMark(testInfo.getMark()); infos.get(infos.size()-1).setTestInfoId(testInfo.getId()); }else{ infos.add(eQuestionService.findByMID(testInfo.getTitleid())); infos.get(infos.size()-1).setType(3); infos.get(infos.size()-1).setMark(testInfo.getMark()); infos.get(infos.size()-1).setTestInfoId(testInfo.getId()); } } model.addAttribute("infos", infos); model.addAttribute("length", infos.size()); model.addAttribute("time", time); model.addAttribute("testId", testId); return "test/answer/answer"; } @RequestMapping("/submit") public String submit(Result result,String userId,String testId){ result.setResultId(UUID.randomUUID().toString()); User user=userService.findOne(userId); Test test=testService.findOne(testId); Answer answer=new Answer(); answer.setAnswerId(UUID.randomUUID().toString()); answer.setState(0); answer.setTest(test); answer.setUser(user); answer.setResult(result); answerService.insert(answer); return "redirect:/test/test/list"; } /*@RequestMapping("/test/answer/listSearch") public String listSearch(){ return "test/answer/jAnswerSearch"; }*/ @RequestMapping("/test/answer/list") public String list(String testName,String courseName,String deptName,String name,Model model){ if("".equals(testName)){ testName=null; } if("".equals(courseName)){ courseName=null; } if("".equals(deptName)){ deptName=null; } if("".equals(name)){ name=null; } List answers = answerService.findAll(testName,courseName,deptName,name); model.addAttribute("answers", answers); return "test/answer/jAnswerList"; } @RequestMapping("/test/answer/delete") public String delete(String answerId){ if(answerId==null||"".equals(answerId)){ return "redirect:/test/answer/list"; } answerService.delete(answerId); return "redirect:/test/answer/list"; } @RequestMapping("/test/answer/toview") public String toview(String answerId,Model model){ if(answerId==null||answerId.contains(",")){ return "redirect:/test/answer/list"; } Answer answer = answerService.findOne(answerId); model.addAttribute("answer", answer); return "test/answer/jAnswerView"; } @RequestMapping(" /test/answer/tocheck") public String tocheck(@RequestParam(required=false)String answerId,Model model){ if(answerId==null||"".equals(answerId)||answerId.contains(",")){ return "redirect:/test/answer/list"; } EQ eq = answerService.checkAnswer(answerId); model.addAttribute("res", eq); return "/test/answer/jAnswerCheck"; } @RequestMapping("/submitAnswer") public String submitAnswer(Integer sumScore,String scoresId,@RequestParam(value="score",required=false)Integer[] scores){ /*Integer[] scoress = {}; Integer sumScoree = Integer.parseInt(sumScore); if(scores!=null){ for (int i=0;i