我在一个类中有一个方法,它应该在点击“下一步”按钮后返回一个 jsp 文件。但它只是删除当前页面的数据并返回当前页面。
这是方法
@RequestMapping(value = "/addQuestion", method = RequestMethod.POST)
public String addQuestion(Model model, @RequestParam(value="question", required = true) String theQuestion , @RequestParam(value="questionId", required = true) Integer questionId, @RequestParam(value="category", required = true) String category, @RequestParam(value="correctAnswer", required = true) String correctAnswer) throws SQLException{
ViewController viewController = new ViewController();
viewController.createQuestion(questionId, theQuestion, category, correctAnswer);
model.addAttribute("question", new Question());
return "qFour";
}
它应该返回 qFour.jsp 但它只返回 addQuestion.jsp,这是它当前所在的页面
最佳答案
您可以从如下方法返回 ModelAndView
。
@RequestMapping(value = "/addQuestion", method = RequestMethod.POST)
public ModelAndView addQuestion(Model model, @RequestParam(value="question", required = true) String theQuestion , @RequestParam(value="questionId", required = true) Integer questionId, @RequestParam(value="category", required = true) String category, @RequestParam(value="correctAnswer", required = true) String correctAnswer) throws SQLException{
ViewController viewController = new ViewController();
viewController.createQuestion(questionId, theQuestion, category, correctAnswer);
return return new ModelAndView("qFour", "question", new Question());
}
关于java方法没有返回正确的类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27123120/