コード例 #1
0
  @RequestMapping(value = "/question/{id}", params = "answer", method = RequestMethod.GET)
  public String answerQuestionForm(@PathVariable("id") Long id, Model model) {
    Question question = questionService.findById(id);
    QuestionAnswer questionAnswer = new QuestionAnswer();
    questionAnswer.setCreationDate(question.getCreationDate());
    questionAnswer.setName(question.getName());
    questionAnswer.setEmail(question.getEmail());
    questionAnswer.setPhone(question.getPhone());
    questionAnswer.setQuestion(question.getQuestion());
    questionAnswer.setAnswer("");

    System.out.println(questionAnswer.getAnswer());
    model.addAttribute("questionAnswer", questionAnswer);
    return "admin/questionAnswer/question";
  }
コード例 #2
0
  @RequestMapping(value = "/question/{id}", params = "answer", method = RequestMethod.POST)
  public String answerQuestion(
      @PathVariable("id") Long id,
      QuestionAnswer questionAnswer,
      RedirectAttributes redirectAttributes,
      Locale locale) {
    questionAnswer.setAnswer(questionAnswer.getAnswer().substring(1));
    Question question = questionService.findById(id);
    questionAnswer.setCreationDate(question.getCreationDate());
    questionAnswer.setName(question.getName());
    questionAnswer.setEmail(question.getEmail());
    questionAnswer.setPhone(question.getPhone());

    questionAnswerService.addQuestionAnswer(questionAnswer);
    questionService.deleteQuestion(id);
    redirectAttributes.addFlashAttribute(
        "message",
        new Message(
            "success",
            messageSource.getMessage("question_answer_save_success", new Object[] {}, locale)));

    return "redirect:/admin/questionAnswer";
  }