@RequestMapping(value = "/ChoiceQuestion", method = RequestMethod.GET) public String ChoiceQuestion( @RequestParam(value = "id", required = true, defaultValue = "1") String id, Model model) { model.addAttribute(QUESTIONNUM, choiceQuestionRepository.count()); model.addAttribute(CHOICEQUESTION, choiceQuestionRepository.findById(Long.valueOf(id))); return "views/answerPage"; }
@RequestMapping(value = "/RecordAndRead", method = RequestMethod.GET) public String RecordAndRead(HttpServletRequest request, Model model) { Map<String, String[]> params = request.getParameterMap(); Set<String> keys = params.keySet(); HashMap<String, String> map = new HashMap<>(); for (String key : keys) { Long qid = Long.valueOf(key); String uanswer = params.get(key)[0]; String answer = choiceQuestionRepository.findOne(qid).getAnswer(); int judge = (answer.equals(uanswer)) ? 1 : 0; ansRecordRepository.save( new AnsRecord(qid, 1L, uanswer, new Timestamp(new java.util.Date().getTime()), judge)); map.put("r" + key, (judge == 1) ? "right" : "wrong"); } model.addAllAttributes(map); model.addAttribute("QuestionNum", keys.size()); return "views/result"; }