我正在使用方法创建一个对象createDummyObjectModel
,然后流程转到一个loadPage
方法,我在其中填充dummyObject
并将其添加到模型中,以便该showDummyObject
方法可以访问它(这是来自页面的 get 调用)。
dummyObject
在我填充loadPage
方法后出现问题,流程再次返回createDummyObjectModel
并清除数据。
解决此问题的最佳方法是什么?我知道@ModelAttribute
方法总是首先被调用。
@Controller
@SessionAttributes( value = {"abcModel"} )
public class myController
{
@RequestMapping( value = "/loadHomePage.html", method = RequestMethod.GET )
public String loadPage( @ModelAttribute( "abcModel" ) DummyObject dummyObject,
ModelMap model )
{
dummyObject = webService.getMyDummyObject("paramters");
model.addAttribute( "abcModel", dummyObject );
return "homepage";
}
@RequestMapping( value = "/getDummyObjectString.html" )
public void showDummObject( @ModelAttribute( "abcModel" ) DummyObject dummyObject,
ModelMap model,
Writer out ) throws IOException
{
String dummyString = dummyObject.toString();
out.write( dummyString );
}
@ModelAttribute( "abcModel" )
public DummyObject createDummyObjectModel()
{
DummyObject dm = new DummyObject();
return dm;
}
}