在 Controller 类中我有一个方法:
@RequestMapping(value = "/newQuestion/{questionId}",method = {RequestMethod.POST, RequestMethod.GET})
public String newQuestion(@PathVariable("questionId") String questionId, Model model,@ModelAttribute("quest") Quest quest ) {
Question question = new Question();
question.setName("New Question");
model.addAttribute("quest", quest);
model.addAttribute("question", question);
return "newQuestion";
}
这是从一个页面重定向并从此页面获取任务对象的值。
重定向后我正确获取了任务对象,但刷新后丢失了..
最佳答案
您不应使用GET
调用此 Controller 方法;在 GET
请求中,@ModelAttribute
对象(例如 quest
)将为 null
。
关于java - spring中的Model对象刷新页面时获取空值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21954404/