java - SSH整合时 getHibernateTemplate()为空
滿天的星座
滿天的星座 2017-06-12 09:26:34
[Java讨论组]
@Repository
public class AuthorAdminDaoImpl implements IAuthorAdminDao {
    @Resource
    private BaseDAO basedao;
public boolean loginAuthorAdmin(AuthorAdmin aa) {
        try {
            String queryString = " from AuthorAdmin  a where a.authorName= ? and a.authorPwd= ? ";
            basedao=new BaseDAO();
            if (basedao.getTemplate() == null) {
                System.out.println("没有获得HibernateTemplate?");
            }
            List find = (List) basedao.getTemplate().find(
                    queryString, aa.getAuthorUsername(), aa.getAuthorPwd());
            if (find != null && find.size() > 0) {
                return true;
            } else {
                return false;
            }
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException();
        }


}
    }
public class BaseDAO extends HibernateDaoSupport{

    public HibernateTemplate getTemplate(){
        return getHibernateTemplate();
    }

}

HibernateTemplate为空不知道为什么?用的是Spring注入






     
    
     

    
        
        
        
        
        
    
    
        
            
        
        
            
                
                    org.hibernate.dialect.MySQLDialect
                
                
                    true
                
                
                    true
                
                
            
        

        
            
                com/lcy/po/DocumentInfo.hbm.xml
                com/lcy/po/ColumnEditorAdmin.hbm.xml
                com/lcy/po/ExpertAdmin.hbm.xml
                com/lcy/po/AttachInfo.hbm.xml
                com/lcy/po/DocumentStateInfo.hbm.xml
                com/lcy/po/ColumnInfo.hbm.xml
                com/lcy/po/MessageInfo.hbm.xml
                com/lcy/po/MagazineEditorAdmin.hbm.xml
                com/lcy/po/BoardInfo.hbm.xml
                com/lcy/po/ExpertAssess.hbm.xml
                com/lcy/po/AuthorAdmin.hbm.xml
            
        
    

    
        
            
        
    

滿天的星座
滿天的星座

全部回复(1)
大家讲道理

本来 Spring 已经帮你把 basedao 注入了你XML里配置好的对象, 你后面又用

basedao = new BaseDAO();

创建了个新对象, 把那个 Spring 给注入的 bean 替换掉了...

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送

Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号