Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.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
spring mvc注释-post上缺少对象值_Spring_Spring Mvc_Annotations - Fatal编程技术网

spring mvc注释-post上缺少对象值

spring mvc注释-post上缺少对象值,spring,spring-mvc,annotations,Spring,Spring Mvc,Annotations,我有一个属性为5的域对象。我在GET方法中预加载对象,并在表单中仅显示一个属性。提交表单时,对象仅包含一个具有值的属性。如何获取其余属性及其值,而不在表单中为每个属性添加隐藏变量 如果不想在隐藏的字段中存储属性,可以在会话中存储对象。在Spring 3中,这可以通过@SessionAttribute注释以声明方式完成: @Controller @RequestMapping("/editBar") // Specifiy the name of the model attribute to be

我有一个属性为5的域对象。我在GET方法中预加载对象,并在表单中仅显示一个属性。提交表单时,对象仅包含一个具有值的属性。如何获取其余属性及其值,而不在表单中为每个属性添加隐藏变量

如果不想在
隐藏的
字段中存储属性,可以在会话中存储对象。在Spring 3中,这可以通过
@SessionAttribute
注释以声明方式完成:

@Controller @RequestMapping("/editBar")
// Specifiy the name of the model attribute to be stored in the session
@SessionAttribute("bar")     
public class BarController {

    @RequestMapping(method = GET) 
    public String form(Map<String, Object> model) {
        model.put("bar", ...);
        ...
    }

    @RequestMapping(method = POST)
    public String submit(@ModelAttribute("bar") Bar bar, BindingResult errors, 
        SessionStatus status) {
        if (!errors.hasErrors()) {
            status.setComplete(); // Clear the session after successful submit
            ...
        } ...
    }
}
@Controller@RequestMapping(“/editBar”)
//指定要存储在会话中的模型属性的名称
@会期贡献(“律师”)
公共类酒吧控制器{
@RequestMapping(方法=GET)
公共字符串表单(映射模型){
模型.推杆(“杆”,…);
...
}
@请求映射(方法=POST)
公共字符串提交(@modeldattribute(“bar”)bar,BindingResult错误,
会话状态(状态){
如果(!errors.hasErrors()){
status.setComplete();//成功提交后清除会话
...
} ...
}
}

如果不想在
隐藏的
字段中存储属性,可以在会话中存储对象。在Spring 3中,这可以通过
@SessionAttribute
注释以声明方式完成:

@Controller @RequestMapping("/editBar")
// Specifiy the name of the model attribute to be stored in the session
@SessionAttribute("bar")     
public class BarController {

    @RequestMapping(method = GET) 
    public String form(Map<String, Object> model) {
        model.put("bar", ...);
        ...
    }

    @RequestMapping(method = POST)
    public String submit(@ModelAttribute("bar") Bar bar, BindingResult errors, 
        SessionStatus status) {
        if (!errors.hasErrors()) {
            status.setComplete(); // Clear the session after successful submit
            ...
        } ...
    }
}
@Controller@RequestMapping(“/editBar”)
//指定要存储在会话中的模型属性的名称
@会期贡献(“律师”)
公共类酒吧控制器{
@RequestMapping(方法=GET)
公共字符串表单(映射模型){
模型.推杆(“杆”,…);
...
}
@请求映射(方法=POST)
公共字符串提交(@modeldattribute(“bar”)bar,BindingResult错误,
会话状态(状态){
如果(!errors.hasErrors()){
status.setComplete();//成功提交后清除会话
...
} ...
}
}