| 一直都很想写一个自己的框架,最近开始动手做了,这两天整理了出来数据访问层的一点实现,同时写了一个小例子,通过下载方便交流,有什么好的建议,和问题还请大家和我交流
暂时没有写web层 仅用了一个main测试的hibernate 整合spring的部分 框架大概是这样的
StudentDAO 继承AbstractService 这个是我使用spring的hibernate摸板封装好的和数据库访问的方法
实现StudentServer 这个接口是和自己业务相关的方法 在调用StudentDAO 的时候使用接口指向子类

 public class Test {

 /** *//**
* @param args
* @throws QueryException
*/
 public static void main(String[] args) throws QueryException {
 /** *//**
* 修改了配置文件用于测试hibernate整合spring是否正常
*/
ApplicationContext context = new FileSystemXmlApplicationContext("src/applicationContext.xml");
context.getBean("sessionFactory");
StudentServer server = (StudentDAO) context.getBean("studentDAO");
 /**//* Student stu = new Student();
stu.setStuname("qq22222222");
stu.setAge(56);
stu.setSex("男");
stu.setPhone(555);
//server.addStudentByCondition(stu);
server.addStudent(stu);*/
List<Student> list = server.getStudent("s", "男");
 for(Student stu : list) {
System.out.println(stu.getStuname());
}
 /** *//**
* 使用select 查询字段
List<Object[]> list = server.getStudent("s", "男");
for(Object[] c : list){
for(Object a : c){
System.out.print(a + "\t");
}
System.out.println();
}
*/
}
}

查询提供了两种方式,一种是使用DAODelegate提供的查询(这和普通的hibernate一样的)
第二种方式是 封装了一个查询类HqlQuery 具体使用例子中有了
对框架提出以下几点:
1、我现在想把AbstractService 这个类在spring注入的时候设置成为静态的 可以提高效率 但不知会有别的什么影响?? 还请哪个朋友指点一下 十分感谢
2、StudentServer 这个接口 和StudentDAO这个类 是一一对应的 StudentDAO这个必须实现接口的方法 而接口中就定义和业务相关的方法 StudentDAO在spring中注入 调用时候使用StudentServer 指向子类
但这样的每在StudentServer 增加一个业务方法就要在dao实现类中添加一个 不知道这样好不好??
还请朋友们帮忙看下
3、因为还没有涉及到web开发 但查询中缺少分页查询,正在整理,有好的分页组件请大家分享下我的邮箱
sunxianchao@gmail.com
有什么好的建议和提议请大家留言 十分感谢!!!
http://exs.mail.qq.com/cgi-bin/downloadfilepart?svrid=12&fid=644bd873e37da73f4ceeef5962b2eeae94fa6298069572c4
提取码:20dc1eb4
希望可以提出您的宝贵意见

|