开发者

How to bind a List for ModelAttribute in spring mvc3

User.java

public class User{
       private String name;
       private List<Link> links;
}

Link.java

public class Link{
       private String addr;
       private String tel;

}

UserController.java

@RequestMapping(value = "user", method = RequestMethod.GET)
public String test(Model model) {
        model.addAttribute("user",new User());
        return "user";

}

@RequestMapping(value = "user", method = RequestMethod.POST)
public String test(User user) {
        System.out.println(user.getName());
        List&l开发者_如何学运维t;Link> links = user.getLinks();
        for(Link link:links){
            System.out.println(link.getAddr());
            System.out.println(link.getTel());
        }

        return "user";
}

user.jsp

[form:form modelAttribute="user" method="post" action="/user"]
[form:input path="name" /]
[form:input path="addr" /]
[form:input path="tel" /]
[form:input path="addr" /]
[form:input path="tel" /]
[input type="submit"][/input]
[/form:form]

Who can tell me How to do it!


[form:form modelAttribute="user" method="post" action="/user"]
[form:input path="name" /]
[form:input path="links[0].addr" /]
[form:input path="links[0].tel" /]
[form:input path="links[1].addr" /]
[form:input path="links[1].tel" /]
[input type="submit"][/input]
[/form:form]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜