Basic Spring MVC Data Binding

后端 未结 4 570
后悔当初
后悔当初 2020-12-10 06:50

I\'m learning Spring MVC and I\'ve looked everywhere to do just a basic controller to view data binding but nothing I\'ve tried as work. I can bind view posting back to cont

4条回答
  •  醉酒成梦
    2020-12-10 07:15

    1) The contents of the modelMap are implicit in the JSP. You don't need to specify 'model' when you access them.

    2) JSP-EL accesses fields via bean property accessors, not invoking methods. You don't specify the 'get' to call an actual method. You use the bean property name. e.g., ${person.firstName} to get the result of person.getFirstName();

    @RequestMapping(value = "/", method = RequestMethod.GET)
    public String home(Model model) {
        Person person = new Person();
        person.setFirstName("Kai");
        person.setLastName("Cooper");
        model.addAttribute("person", person);
        return "home";
    }
    

    `

    
    
    
        
            FirstName: ${person.firstName}
            LastName: ${person.lastName}
        
    
    

提交回复
热议问题