0
I have to return values from two modelandview methods to a single jsp `mySoftwarelist.jsp` where i have two tables. Here i have two seperate methods for returning array list 

    ModelAndView getLegacySuiteList()
    ModelAndView getSuiteList()

i returned the arraylist `mySoftwareList`,`mySoftwareLegacyList` to the same view `swl_mySoftwareList` as

public ModelAndView getSuiteList(HttpServletRequest request, HttpServletResponse response) throws Exception
{
ArrayList mySoftwareList = new ArrayList();    
 try{
MySoftwareListHelper mySoftwareListHelper = new MySoftwareListHelper();
userEmailAddr =user.getEmailaddress();      
mySoftwareList = mySoftwareListHelper.getSuites(userEmailAddr);

}
catch(Exception e) {
 e.printStackTrace();
}
ModelAndView mnv = new ModelAndView("swl_mySoftwareList","mySoftwareList",mySoftwareList);
return mnv;

}

public ModelAndView getLegacySuiteList(HttpServletRequest request, HttpServletResponse response) throws Exception
{       
ArrayList mySoftwareLegacyList = new ArrayList();       
try{
MySoftwareListHelper mySoftwareListHelper = new MySoftwareListHelper();
userEmailAddr =user.getEmailaddress();
mySoftwareLegacyList = mySoftwareListHelper.getLegacySuites(userEmailAddr);
}catch(Exception e){
e.printStackTrace();
}

ModelAndView mnv = new ModelAndView("swl_mySoftwareList","mySoftwareLegacyList",mySoftwareLegacyList); 返回mnv;

}

但它只返回模型mySoftwareList。我希望两个数组列表中的数据都用于同一个 jsp。

4

2 回答 2

2

在返回视图之前,您需要将这两个列表分别添加到同一个 mnv 对象中。

ModelAndView mnv = new ModelAndView("swl_mySoftwareList","mySoftwareList",mySoftwareList); 
mnv.addObject("mySoftwareLegacyList",mySoftwareLegacyList);

return mnv;

希望这可以帮助。

干杯。

于 2012-05-15T13:24:24.743 回答
0

我认为最好的做法是使用从两个实体获取所需属性的 DTO 对象,然后将该 DTO 对象传递给视图。

于 2012-05-18T05:25:23.833 回答