gpt4 book ai didi

java方法没有返回正确的类型

转载 作者:行者123 更新时间:2023-11-30 11:11:59 25 4
gpt4 key购买 nike

我在一个类中有一个方法,它应该在点击“下一步”按钮后返回一个 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com