欢迎来到天天文库
浏览记录
ID:51584857
大小:38.83 KB
页数:18页
时间:2020-03-13
《基于泛型DAO的Facade设计模式.docx》由会员上传分享,免费在线阅读,更多相关内容在学术论文-天天文库。
1、在做管理系统时。通常基于Facade模式的系统持久化层要写许多Dao。这些dao里面的方法又是重复的,那么有没有什么好的方法来统一利用一个公共的Dao。答案是可以的。这里我们接触到JDK5.0里面的一个新特性:泛型。关于泛型的含义我这里就不再解释了。下面我们以一个对用户管理和新闻管理的来示范。首先是2个POJO。我这里只列出User POJO。(基于注释的Pojo)Java代码1. 2.package com.oa; 3. 4.import javax.persistence.Column; 5.import javax.persistence.E
2、ntity; 6.import javax.persistence.GeneratedValue; 7.import javax.persistence.GenerationType; 8.import javax.persistence.Id; 9.import javax.persistence.Table; 10. 11.@Entity 12.@Table(name = "tb_user") 13.public class User { 14. 15. @Id 16. @GeneratedValue(strategy =
3、 GenerationType.IDENTITY) 17. private int id; 18. 19. @Column(name = "username", length = 15) 20. private String username; 21. 22. @Column(name = "password", length = 15) 23. private String password; 24. 25. public int getId() { 26. return id; 27.
4、 } 28. 29. public void setId(int id) { 30. this.id = id; 1. } 2. 3. public String getUsername() { 4. return username; 5. } 6. 7. public void setUsername(String username) { 8. this.username = username; 9. } 10. 11. public Str
5、ing getPassword() { 12. return password; 13. } 14. 15. public void setPassword(String password) { 16. this.password = password; 17. } 18. 19.} 20. 21. packagecom.oa;importjavax.persistence.Column;importjavax.persistence.Entity;importjavax.persisten
6、ce.GeneratedValue;importjavax.persistence.GenerationType;importjavax.persistence.Id;importjavax.persistence.Table;@Entity@Table(name="tb_user")publicclassUser{@Id@GeneratedValue(strategy=GenerationType.IDENTITY)privateintid;@Column(name="username",length=15)privateStringusername;@Co
7、lumn(name="password",length=15)privateStringpassword;publicintgetId(){returnid;}publicvoidsetId(intid){this.id=id;}publicStringgetUsername(){returnusername;}publicvoidsetUsername(Stringusername){this.username=username;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(
8、Stringpassword){thi
此文档下载收益归作者所有