Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/batch-file/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Spring@SessionAttribute在控制器之间共享?_Java_Spring_Spring Mvc - Fatal编程技术网

Java Spring@SessionAttribute在控制器之间共享?

Java Spring@SessionAttribute在控制器之间共享?,java,spring,spring-mvc,Java,Spring,Spring Mvc,我使用的是Spring4.3.7,我得到了两个表单控制器,在相应的视图中使用SpringFormTaglib呈现表单。为了在请求之间保留表单数据(用于呈现无效表单),我将它们存储在SessionAttributes中 LabCreateController: @Controller @RequestMapping(path = "/labs/create") @SessionAttributes("form") public class LabCreateController { @M

我使用的是Spring4.3.7,我得到了两个表单控制器,在相应的视图中使用SpringFormTaglib呈现表单。为了在请求之间保留表单数据(用于呈现无效表单),我将它们存储在SessionAttributes中

LabCreateController:

@Controller
@RequestMapping(path = "/labs/create")
@SessionAttributes("form")
public class LabCreateController {

    @ModelAttribute("form")
    public LabCreateForm form() {
        return new LabCreateForm();
    }

    @GetMapping
    public String showForm() {
        return "lab_create";
    }

}
@Controller
@RequestMapping(path = "/group/{id}/wall")
@SessionAttributes("form")
public class WallController {

    @ModelAttribute("form")
    public PostCreateForm form() {
        return new PostCreateForm();
    }

    @GetMapping(path = "/new")
    public String newPostGet() {
        return "communities_newpost";
    }

}
墙控制器:

@Controller
@RequestMapping(path = "/labs/create")
@SessionAttributes("form")
public class LabCreateController {

    @ModelAttribute("form")
    public LabCreateForm form() {
        return new LabCreateForm();
    }

    @GetMapping
    public String showForm() {
        return "lab_create";
    }

}
@Controller
@RequestMapping(path = "/group/{id}/wall")
@SessionAttributes("form")
public class WallController {

    @ModelAttribute("form")
    public PostCreateForm form() {
        return new PostCreateForm();
    }

    @GetMapping(path = "/new")
    public String newPostGet() {
        return "communities_newpost";
    }

}
我在浏览器中打开
/labs/create
,一切正常。然后我打开
/group/4/wall/new
,得到以下错误:

bean类的无效属性“text” […LabCreateForm]

i、 这意味着
LabCreateController
中的属性
form
以某种方式传递给
WallController
,尽管Spring文档中说:

使用此注释指示的会话属性对应于 特定处理程序的模型属性

我相信这意味着它们不应该在控制器之间共享。也说是从春天三号开始


是虫子还是我遗漏了什么?如果没有,在一个控制器中存储表单的适当方式是什么?

从两个控制器中删除SessionAttribute注释,并在每个控制器上仅保留ModelAttribute方法。从两个控制器中删除SessionAttribute注释,并在每个控制器上仅保留ModelAttribute方法。