2017-05-05 22 views
0

我有一個控制器,它包含兩種不同的請求方法:POST和GET並且它們具有不同的URL映射。我想在視圖更新形式:Spring框架:在控制器中,從不同的URL獲取模型

@RequestMapping(value="/sudent.do", method=RequestMethod.GET) 
protected ModelAndView getStudent(ModelMap model, BindingResult result){ 
Student student = new Student(); 
..... 
model.addAttribute("student", student); 
return new ModelAndView("student"); } 

而另一種方法

@RequestMapping(value="/sudentUpdate.do", method=RequestMethod.GET) 
protect ModelAndView studentUpdate(@ModelAttribute("student") Student student, Binding result) {..} 

我在這兩種方法得到的模型是不同的。

有了Spring Framework 4,有沒有辦法在控制器的兩種不同方法中使用相同的模型?

謝謝!

+0

或者你可以採取在HttpServletResponse的在你的控制方法,並返回一個重定向。 –

+0

你的意思是使用HttpServletResponse來傳遞模型?我怎樣才能做到這一點?謝謝! – CMPE

回答

0

使用@SessionAttributes("..")與bean ID名字爲我工作

相關問題