你当我是浮夸吗 2019-01-08 18:12 采纳率: 0%
浏览 944

maven 里模块拆分时, 我dao层的值传不进去service层

Running com.mycompany.app.service.UserServiceTest
**********service 层testQueryPassword******开始******
Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 0.081 sec <<< FAILURE!
testQueryPassword(com.mycompany.app.service.UserServiceTest) Time elapsed: 0.022 sec <<< ERROR!
java.lang.NullPointerException

    public String getUserPassword(String userName) {
        String name = "";
        Session session = null;
        try {
            session = HibernateUtils.getSession();
            session.beginTransaction();

            List result =  session.createQuery("select password from User where name = :name").setParameter("name", userName).list();

            if(result !=null && result.size()>0) {
                name = (String) result.get(0);
            } else {
                name = "null";
            }

            System.out.println("****************************");
            System.out.println(name);
            session.getTransaction().commit();
        }catch(Exception e) {
            e.printStackTrace();
            session.getTransaction().rollback();
        }finally {
            HibernateUtils.closeSession(session);
        }
        return "zhanshan";
    }


}



//service层

package com.mycompany.app.service;

import com.mycompany.app.dao.UserDao;

public class UserServiceImpl implements UserService {
    private UserDao userdao;
    public String getUserPassword(String name) {
        // TODO Auto-generated method stub
        return userdao.getUserPassword(name);
    }

}

  • 写回答

3条回答 默认 最新

  • 浮生cium 2019-01-08 18:40
    关注

    @Autowired

    评论

报告相同问题?

悬赏问题

  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。
  • ¥15 各位 帮我看看如何写代码,打出来的图形要和如下图呈现的一样,急
  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd