简体   繁体   English

如何在Spring MVC中删除会话属性

[英]How to remove the session attributes in spring mvc

I am trying to deploy a Spring mvc application. 我正在尝试部署Spring mvc应用程序。 I have wizard like form which is filled by user and I retain the content of each form in the wizard by utilizing session, until the last page and then user confirms and content is saved. 我有类似表单的向导,该表单由用户填写,我利用会话将向导中的每个表单的内容保留到最后一页,然后用户确认并保存内容。 Then the controller redirect to another page. 然后,控制器重定向到另一个页面。 But here I have a form with all previous session attributes, all presented in the form. 但是在这里,我有一个表单,其中包含所有先前的会话属性,所有属性都以该表单呈现。 My question is is there any method to remove all the session attributes from a controller before redirecting to another page The review page controller: 我的问题是在重定向到另一个页面之前,是否有任何方法可以从控制器中删除所有会话属性。

@RequestMapping("/review")
    public String review(@ModelAttribute Resource resource){
        // do somthing
        return "course_review";
    }

and save course controller 并保存课程控制器

@RequestMapping("/save")
public String save(@ModelAttribute Resource resource) {
    // do somthing
    return "redirect:/course/add";
}

and save contoler redirect to /course/add which is controlled by 并保存contoler重定向到/course/add ,该路径由

@RequestMapping("/add")
    public String add(Model model) {
        //do somthing
        return "course_add";
    }

The Controller class is annotated with Controller类带有注释

@Controller
@RequestMapping("/course")
@SessionAttributes("course")

Please advise. 请指教。

Look at SessionStatus helper class. 查看SessionStatus帮助程序类。

From the docs 来自docs

... attributes will be removed once the handler indicates completion of its conversational session. 一旦处理程序指示其会话会话完成,...属性将被删除。

@RequestMapping("/save")
public String save(@ModelAttribute Resource resource, SessionStatus status) {
    status.setComplete();
}

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

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