猿问

ssh项目getHibernateTemplate().find()出现空指针异常

public Employee findByUsernameAndPassword(Employee employee) {
        String hql = "from Employee where username = ? and password = ?";
        List<Employee> list = this.getHibernateTemplate().find(hql,employee.getUsername(),employee.getPassword());
        if(list.size()>0) {
            return list.get(0);
        }
        return null;
    }

异常:

2017-09-26 11:03:49 [信息] Exception occurred during processing request: null
java.lang.NullPointerException
    at cc.test.employee.dao.impl.EmployeeDaoImpl.findByUsernameAndPassword(EmployeeDaoImpl.java:18)
一只萌萌小番薯
浏览 658回答 5
5回答

慕运维8079593

行号?到底employee是null还是list?

牛魔王的故事

打印下getHibernateTemplate吧

蝴蝶不菲

employee是否为null?

慕仙森

HibernateTemplate 有注入sessionfactory么?

呼如林

调用this.getHibernateTemplate() 报空指针异常了或者 employee 为null了。
随时随地看视频慕课网APP

相关分类

Java
我要回答