首页 新闻 会员 周边

struts2与hibernate结合使用出现的问题,求解

0
悬赏园豆:50 [已关闭问题] 关闭于 2016-09-09 19:57
复制代码
 1 //action中的代码
 2 public String execute() throws Exception {
 3         EmployeeDaoImpl dao=new EmployeeDaoImpl();    
 4     String str=dao.loginUser(username, password,status).toString();
 5         ServletActionContext.getResponse().setContentType("text/html;charset=utf-8");
 6         System.out.println(str);
 7         ServletActionContext.getResponse().getWriter().println(str);
 8         return null;
 9     }
10 
11 //EmployeeDaoImpl 类中的代码如下(测试无问题)
public List<TEmployee> loginUser(String username, String password, Integer role_id) {
        String hql="select a from TEmployee a inner join a.TRole b" +
                " where a.employeeName=? and a.password=? and b.roleId=?";
        List<TEmployee> list=Template.select(hql, new Object[]{username,password,role_id}); return list; }
//Template类如下
@SuppressWarnings("unchecked")
    public static <T>List<T> select(String hql,Object[]params){
              //debug时到此程序终止,JUnit测试成功
        Session session=HibernateSessionFactory.getSession();
        Query query=session.createQuery(hql);
        for (int i = 0; i < params.length; i++) {
            query.setParameter(i, params[i]);
        }
        List<T> list=query.list();
        HibernateSessionFactory.closeSession();
        return list;
    }

 



 


究其一生的主页 究其一生 | 初学一级 | 园豆:4
提问于:2016-09-07 18:38
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册