接上例:http://blog.csdn.net/kunshan_shenbin/archive/2008/09/03/2873943.aspx
User对Room是多对一的关系,那么反过来Room对User就是一对多的关系了。
User.java:
1.package com.hb3.pack_17.model;2.3.public class User {4. 5. private Integer id;6. private String name;7.8. public User() {9. }10. 11. public Integer getId() {12. return id;13. }14. public void setId(Integer id) {15. this.id = id;16. }17. public String getName() {18. return name;19. }20. public void setName(String name) {21. this.name = name;22. }23.}
Room.java:
1.package com.hb3.pack_17.model;2.3.import java.util.Set;4. 5.public class Room {6. 7. private Integer id;8. private String address;9. private Set<User> users;10.11. public Room() {12. }13.14. public Integer getId() { 15. return id;16. } 17. public void setId(Integer id) { 18. this.id = id;19. }20. public String getAddress() { 21. return address;22. }23. public void setAddress(String address) { 24. this.address = address;25. }26. public Set<User> getUsers() {27. return users;28. }29. public void setUsers(Set<User> users) {30. this.users = users;31. }32. public void addUser(User user) {33. users.add(user);34. }35. public void removeUser(User user) {36. users.remove(user);37. }38.}
以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索string
, private
, integer
, public
, users
address
,以便于您获取更多的相关知识。
时间: 2024-09-29 17:01:22