到 Google 资讯主页   
EasyJF首页   资料   源码   软件    论坛   网站    
   使用帮助    
    该信息为本站MyRSS系统缓存内容,部分图片及附件有可能无法正常使用.easyjf.comwww.blogjava.net无关,不对该信息负责.通过http://www.blogjava.net/lifenote/archive/2007/12/10/166636.html访问该信息的原始内容.
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   
写了一个hibernate 整合spring 的小框架
作者:LifeNote 来源:www.blogjava.net  发布时间:2007-12-11 10:57:53.617

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

 



LifeNote 2007-12-10 13:41 发表评论

 
相关文章
 
页面功能  【加入收藏】 【推荐给朋友】 【字体:  】 【关闭】   


EasyJF.com 2006 隐私政策 使用EasyJF前必读