简体   繁体   English

从先前的ModelAndView访问对象

[英]accessing object from previous ModelAndView

通过参考链接:如果已修改public ModelAndView sendEmail() {}并说其他对象(例如CollectionHashMap将添加到Model Object中, 那么如何重定向到另一个URI并从先前public ModelAndView sendEmail() {} 访问对象,那么您将如何在/nextPageclass方法中进行访问?

If possible I would just stick it into the HttpSession object: 如果可能的话,我将其粘贴到HttpSession对象中:

    public ModelAndView something(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.setAttribute("name", "object");
    return new ModelAndView(new RedirectView("nextPageclass"));
}

This should make the values available during the entire user's sessions rather than just on the individual page request. 这应该使值在整个用户会话期间可用,而不仅仅是在单个页面请求上可用。 You will end up having to manage the state of Session attributes but this provides a way to make the data available on the next page or any page thereafter without having to consistent get() and set() the value. 您最终将不得不管理Session属性的状态,但这提供了一种使数据在下一页或之后的任何页面上可用的方式,而不必使get()和set()的值保持一致。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM