首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

新手使用find()有关问题求助

2011-12-04 
新手使用find()问题求助。我的代码:importjava.util.Listimportorg.acegisecurity.providers.encoding.Md5

新手使用find()问题求助。
我的代码:

import   java.util.List;

import   org.acegisecurity.providers.encoding.Md5PasswordEncoder;
import   org.acegisecurity.providers.encoding.PasswordEncoder;
import   org.apache.commons.logging.Log;
import   org.apache.commons.logging.LogFactory;
import   org.springside.core.dao.HibernateEntityDao;

import   com.my.security.model.User;


public   class   CustomerUser   extends   HibernateEntityDao <User> {
  final   Log   buzzLog   =   LogFactory.getLog(Constants.BUSINESS_LOG);


public   int   UserCheck(String   userid,   String   passwd){
    buzzLog.info( "---   Check   Begin   --- ");
    int   ret   =   1;
    String   hql;
    String   passwd2;
    PasswordEncoder   passwordEncoder   =   new   Md5PasswordEncoder();
    passwd2   =   passwordEncoder.encodePassword(passwd,   null);
    hql   =   "from   user   u   where   number=?   and   passwd=? ";
    try   {
      buzzLog.info( "---find   begin   ---\n "   +   hql);
      List   userList   =   find(hql,userid,passwd2);
      if   (   userList.size()   >   0)   {
        ret   =   0;
        }
    }
    catch(Exception   e){
      buzzLog.info( "---find   error   --- ");
      e.printStackTrace();
      ret   =   -1;
    }
    return   ret;
  }
public   List   find(String   hql,   Object...   values)   {
Assert.hasText(hql);
return   getHibernateTemplate().find(hql,   values);
}
}
 

执行时报错:

2007-07-09   13:05:26,375   INFO   [business]   -   <---   Check   Begin   --->
2007-07-09   13:05:26,421   INFO   [business]   -   <---find   begin   ---
from   ss_users   u   where   number=?   and   passwd=?>
2007-07-09   13:05:26,421   INFO   [business]   -   <---find   error   --->
java.lang.NullPointerException

  at   org.springside.core.dao.HibernateGenericDao.find(HibernateGenericDao.java:159)
  at   com.my.commons.CustomerUser.UserCheck(CustomerUser.java:34)   <就是List   userList   =   find(hql,userid,passwd2);>
  at   sun.reflect.NativeMethodAccessorImpl.invoke0(Native   Method)
  at   sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
  at   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
  at   java.lang.reflect.Method.invoke(Method.java:585)
  at   org.apache.struts.actions.DispatchAction.dispatchMethod(DispatchAction.java:270)
  at   org.apache.struts.actions.DispatchAction.execute(DispatchAction.java:187)
  at   org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
  at   org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
  at   org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)


  at   org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
  at   javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
  at   javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
  at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
  at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  at   org.extremecomponents.table.filter.AbstractExportFilter.doFilter(AbstractExportFilter.java:49)
  at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  at   org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:173)
  at   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
  at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  at   org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:78)
  at   org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
  at   org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
  at   org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
  at   org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
  at   org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
  at   org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
  at   org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
  at   org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
  at   org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
  at   org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
  at   org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
  at   org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
  at   org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
  at   org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
  at   java.lang.Thread.run(Thread.java:595)



[解决办法]
有意思, find(hql,userid,passwd2) 编译能通过?
public List find(String hql, Object... values) 这是何方神圣?

用这种方法:
List userList = getHibernateTemplate().find(hql,new Object[]{userid});
[解决办法]
悄悄说一句
那是JAVA5的可变参数列表
去GOOGLE一下吧

热点排行