日期:2014-05-18  浏览次数:20740 次

大家看看这个哪里错误了
AsminuserDAO中的一个方法
public   List   findByStr(String   queryString,   Map   paramMap)   {
//   TODO   自动生成方法存根
  log.debug( "finding   Adminuser   by   String   sql:   ");
                try   {
                     
      return   getHibernateTemplate().find(queryString,   paramMap);//是不是这句有问题
                }   catch   (RuntimeException   re)   {
                      log.error( "find   by   property   name   failed ",   re);
                      throw   re;
                }


}


被另一个程序调用
public   class   ServiceImp   implements   IService   {
private   AdminuserDAO   adminuserDAO;
public     AdminuserDAO   getAdminuserDAO(){
return   adminuserDAO;
}
public   void   setAdminuserDAO(AdminuserDAO   adminuserDAO){
this.adminuserDAO=adminuserDAO;
}
//private   static   String   hql   = "from   vo.Adminuser   u   where   u.UserName=? ";

public   boolean   isAdmin(String   username,   String   password)   {


String   queryString= "from   Adminuser   as   model   where     model.userName=?   and   password=? ";
Map   paramMap   =   new   HashMap();

paramMap.put( "userName ",   username);
paramMap.put( "password ",   password);
                  List   AdminList=adminuserDAO.findByStr(queryString,   paramMap);
if   (AdminList.size()> 0)   {

return   true;

}

return   false;

}

}

错误信息是
javax.servlet.ServletException:   Expected   positional   parameter   count:   2,   actual   parameters:   [{userName=maxin,   password=maxin}]   [from   Adminuser   as   model   where   model.userName=?   and   password=?];   nested   exception   is   org.hibernate.QueryException:   Expected   positional   parameter   count:   2,   actual   parameters:   [{userName=maxin,   password=maxin}]   [from   Adminuser   as   model   where   model.userName=?   and   password=?]
大家多多指教谢谢

------解决方案--------------------
Map paramMap = new HashMap();
别用这个

用Object[] ob = new Object[]{username, password};

最好的还是封装到一个FROMBEAN里或者POJO类里