第一次用spring mvc框架,不是很懂。页面提交表单,控件属性都是对象.属性形式,在controller中也声明了对象,set方法也有,不能想struts那样将页面属性值注入到对象中去???

解决方案 »

  1.   

    可以的哦   比方说  struts2    <input name="user.name"/>   Action中需要有user对象
    spring   <input name="name"/>      @controller 中   @RequestMapping("/***")方法参数直接给 user对象即可
      

  2.   

    你action中的对象是不是又实例化了一遍,如果这样对象肯定为空。
      

  3.   

     @RequestMapping(value = "/user/add", method = {RequestMethod.POST})
        public String add(Model model, @ModelAttribute("command") @Valid UserModel command, BindingResult result) {
            
            //如果有验证错误 返回到form页面
            if(result.hasErrors()) {
                model.addAttribute(Constants.COMMAND, command);
                return toAdd(model);
            }
             userService.save(command);
            return "redirect:/user/success";
        }@Valid   这个接受对象
      

  4.   


    没有。就在全局声明了,然后提供了set方法。
      

  5.   

     <input name="user.name"/> 页面是对象.属性 那action中把get方法也写了试试。不应该接不到的。
      

  6.   

    action中有user对象,并且user.Clsss中有name属性,在action中提供get和set方法应该是可以的,你尝试一下