前端html用一个表单来映射后台多个对象
public class entity1 { private String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } private String name; } public class entity2 { private String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } private String name; } public class entity3 { private String id; public String getId() { return id; } public void setId(String id) { this.id = id; } public String getName() { return name; } public void setName(String name) { this.name = name; } private String name; } public class mytestAction extends ActionSupport{ private entity1 entity1; private entity2 entity2; private entity3 entity3; public String save() { return "success" } }
技术交流QQ群:15129679
<!DOCTYPE HTML> <html lang="en-US"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <form action=""> <input type="text" name="entity1.id" /> <input type="text" name="entity1.name" /> <input type="text" name="entity2.id" /> <input type="text" name="entity2.name" /> <input type="text" name="entity3.id" /> <input type="text" name="entity3.name" /> </form> </body> </html>
表的name值我们用了对象的名称然后序列化表单提交到后台,后台就映射到了三个对象是不是很easy!