这两天整理了出来数据访问层的一点实现,同时写了一个小例子,通过下载方便交流,有什么好的建议,和问题还请大家和我交流
暂时没有写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
希望可以提出您的宝贵意见

 

posted on 2007-12-10 13:41 LifeNote 阅读(1743) 评论(7)  编辑  收藏 所属分类: JavaHibernateSpring
Comments
  • # re: 写了一个hibernate 整合spring 的小框架
    discuz!
    Posted @ 2007-12-10 15:53
    不错,学习一下  回复  更多评论   
  • # re: 写了一个hibernate 整合spring 的小框架
    路过
    Posted @ 2007-12-10 18:04
    嚣张个啥!!!  回复  更多评论   
  • # re: 写了一个hibernate 整合spring 的小框架
    发给我看看吧
    Posted @ 2007-12-10 21:20
    leonardo_rong@126.com   回复  更多评论   
  • # re: 写了一个hibernate 整合spring 的小框架
    LifeNote
    Posted @ 2007-12-11 12:45
    附下载地址及提取码  回复  更多评论   
  • # re: 写了一个hibernate 整合spring 的小框架
    LifeNote
    Posted @ 2007-12-11 13:10
    麻烦看完了提点意见 多谢  回复  更多评论   
  • # re: 写了一个hibernate 整合spring 的小框架
    TonySoft
    Posted @ 2007-12-11 13:53
    朋友,标题太大了

    你这不算"整合",而且结构太混乱,也许我说的重了点,但是希望你能平心静气的坐下来读一读"Spring in action"和"J2EE without EJB"这两本书.  回复  更多评论   
  • # re: 写了一个hibernate 整合spring 的小框架
    LifeNote
    Posted @ 2007-12-11 14:33
    只是把hibernate 和 spring两个框架整合在一起啊 就是封装了一个数据访问的dao类而已 题目是不大好
    J2EE without EJB 这本书是在看呢 写的比较注重实践 看的有些难度
    还是多谢TonySoft 的意见   回复  更多评论   

只有注册用户登录后才能发表评论。


网站导航: