Spring MVC3.05 Contorler跳转传值问题,请教如何解决?
DelMobilecardsController --- 删除操作ContorlerListMobilecardsController --- 查询操作Contorler
无论 删除是否成功 还是失败,都会跳转到查询 Contorler去。
删除操作失败,会抛出异常,如何把异常信息传给ListMobilecardsController?
Ctorller 1(删除操作):
@Controller
public class DelMobilecardsController
{
private static final Logger logger = LoggerFactory.getLogger(DelMobilecardsController.class);
@RequestMapping(value = "/delMobilecards.action", method = RequestMethod.POST)
public ModelAndView delMobilecardsAction(@RequestParam(value = "id", required = false)
Long[] ids)
{
ModelAndView modelAndView = new ModelAndView("mobilecard/listMobilecards");
try
{
MobilecardService mobilecardService = (MobilecardService) BSSBeanFactory
.getBean(MobilecardService.BEAN_NAME);
mobilecardService.delMobilecards(ids);
}
catch (DtuException e)
{
logger.error(e.getErrorCode(), e);
BindingResult bindingResult = new BindException(e, "");
bindingResult.reject(e.getErrorCode());
modelAndView.addObject(bindingResult.getModel());
}
return modelAndView;
}
}
Ctorller 2(查询操作):
--------------------编程问答-------------------- 从一个控制器跳转到另一个控制器,楼主应该使用forward:前缀在mobilecard/listMobilecards(或许应该是/listMobilecards.action)前,否则会奔视图去了。
@Controller
public class ListMobilecardsController
{
@RequestMapping(value = "/listMobilecards.action", method = RequestMethod.GET)
public ModelAndView listMobilecardsAction(@RequestParam(value = "curPage", required = false)
Long curPage)
{
ModelAndView modelAndView = new ModelAndView("mobilecard/listMobilecards");
if (null == curPage)
{
curPage = 1l;
}
Pager pager = new Pager();
pager.setCurPage(curPage);
MobilecardService mobilecardService = (MobilecardService) BSSBeanFactory.getBean(MobilecardService.BEAN_NAME);
mobilecardService.findMobilecardsByPager(pager);
modelAndView.addObject("pager", pager);
return modelAndView;
}
}
异常传递,最简单的做法就是放Model中,当普通对象传吧。 --------------------编程问答-------------------- 楼上正解 --------------------编程问答-------------------- 简单说就是把 excpetion instance 塞 到 request 里面。 转发到下一个环节。 --------------------编程问答-------------------- 你好,我刚接触spring3 mvc做项目,能发一份能运行的事列给我吗,谢谢!!!!!!!!
补充:Java , Java EE