我试图在我的控制器类中使用@SessionAttributes,如下所示:
@Controller
@SessionAttributes({"calMethods", "taxList"})
@RequestMapping("/secure")
public class reportController extends BaseController {
//..
@ModelAttribute("taxList")
public List<multiCalDto> getTaxList() {
return new ArrayList<multiCalDto>();
}
//....
@RequestMapping(value = "/confirmCal.html", method = RequestMethod.GET)
public ModelAndView launchconfirmCal(HttpServletRequest request, @RequestParam("seqNo") String seqNo) {
...........
ModelAndView modelAndView = new ModelAndView("confirmCalView");
modelAndView.addObject("taxList", calBean.getTaxList());
return modelAndView;
}
@RequestMapping(value = "/executeCalPay.html", method = RequestMethod.POST)
public ModelAndView executeCalPay(HttpServletRequest request, @ModelAttribute("taxList") List<multiCalDto> taxList) {
// ............
ModelAndView modelAndView = new ModelAndView("calView");
System.out.println("taxList -- "+taxList);
return modelAndView;
}
}
我在launchconfirmCal()中添加了taxList,并试图在executeCalPay()中访问它。 我尝试在添加到modelAttribute之前打印taxList,大小为12,当我在executeCalPay()中退出时,它显示为null。 我没有改变它在JSP中的价值。
答案 0 :(得分:0)
删除或注释掉此方法并重试
@ModelAttribute("taxList")
public List<multiCalDto> getTaxList() {
return new ArrayList<multiCalDto>();
}
@ModelAttribute注释方法在 ALL 请求映射方法之前调用,因此它会在调用post方法之前重置taxList