我在类中有一个方法,并且一旦命中“下一个”按钮,就会返回一个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,这是它当前所在的页面
答案 0 :(得分:1)
您可以从以下方法返回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());
}
答案 1 :(得分:0)
由于您没有提供配置文件内容,因此很难准确确定需要更改的内容。但我认为您的 addQuestion 方法的返回类型需要 ModelAndView 而不是 String 才能达到您的目的。试试这个return语句:
return new ModelAndView("qFour.jsp");