我尝试在我的 Controller 类中使用 @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 中的值。
最佳答案
删除或注释掉此方法并重试
@ModelAttribute("taxList")
public List<multiCalDto> getTaxList() {
return new ArrayList<multiCalDto>();
}
@ModelAttribute 注释方法在 ALL 请求映射方法之前调用,因此它会在调用 post 方法之前重置您的taxList
关于java - Spring @SessionAttributes 返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28863910/