不管数据库里有没有值,都报空指针以下是代码:
/**
 * 跳转到薪酬标准登记
 * @param mapping
 * @param form
 * @param request
 * @param response
 * @return
 * @throws Exception
 */
public ActionForward toSalaryCheckIn(ActionMapping mapping,
ActionForm form, HttpServletRequest request,
HttpServletResponse response) throws Exception {

String id=salaryStandardCheckInBiz.getMaxStandarId();//获得最大薪酬编号,如果没有返回默认
salaryStandard.setStandardId(id);//薪酬编号

salaryStandard.setRegistTime(new Date());//登记时间

request.setAttribute("salaryStandard", salaryStandard);

List confList=salaryStandardCheckInBiz.getItemName("薪酬设置");//根据属性的种类查询出薪酬项目

request.setAttribute("confList", confList);


return mapping.findForward("salaryStandardCheckIn");//跳转到薪酬标准登记页面
}daoImpl:
/**
 * 查询薪酬标准信息的最大薪酬标准单编号
 */
public String getMaxStandarId() {
String hql = "select MAX(s.standardId) from SalaryStandard s";
String id = null;
try{
List list = super.getHibernateTemplate().find(hql);
Iterator itr = list.iterator();
while(itr.hasNext()) {
SalaryStandard salaryStandard = (SalaryStandard) list.get(0);
if(salaryStandard.getStandardId()==null){
id="1000000001";
}else{
id=salaryStandard.getStandardId();//获得薪酬编号
}
}
}catch(RuntimeException e){
e.printStackTrace();
}

return id;
}
applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans 
http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

<!-- 事务管理器 -->
<bean id="myHibTxManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"></property>
</bean>
<!-- 实体bean  -->
<bean id="salaryStandard" class="org.hr.entity.SalaryStandard"/>

<!-- dao -->
<bean id="humanFileDAO" class="org.hr.dao.impl.HumanFileDAOImpl">
  <property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="salaryStandardCheckInDao" class="org.hr.dao.impl.SalaryStandardCheckInDaoImpl">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>

<!-- biz -->
<bean id="humanFileBiz" class="org.hr.biz.impl.HumanFileBizImpl"/>
<bean id="salaryStandardCheckInBiz" class="org.hr.biz.impl.SalaryStandardCheckInBizImpl"/>
<!-- action -->
<bean name="/humanFile" class="org.hr.struts.action.HumanFileAction"/>
<bean name="/salaryStandardCheckIn" class="org.hr.struts.action.SalaryStandardCheckInAction"/>






   <!-- 事务通知  -->
<tx:advice id="txadvice" transaction-manager="myHibTxManager">
<tx:attributes>
<tx:method name="get*" propagation="SUPPORTS" read-only="true" />
<tx:method name="load*" propagation="SUPPORTS" read-only="true" />
<tx:method name="search*" propagation="SUPPORTS" read-only="true" />
<tx:method name="*" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>

<aop:config>
<aop:pointcut id="bizMethods" expression="execution(* org.hr..*.*(..))"/>
<aop:advisor advice-ref="txadvice" pointcut-ref="bizMethods"/>
</aop:config>   <!-- 数据源 -->
    <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource" destroy-method="close">
    <property name="driverClass" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
    <property name="jdbcUrl" value="jdbc:sqlserver://localhost:1433;databaseName=HR_DB"/>
    <property name="user" value="sa"/>
    <property name="password" value="123"/>
  </bean>

<!--sessionFactory 类-->
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">
<property name="dataSource">
<ref local="dataSource" />
</property>
<property name="mappingResources">
<list>
<value>org/hr/entity/ConfigFileFirstKind.hbm.xml</value>
<value>org/hr/entity/ConfigFileSecondKind.hbm.xml</value>
<value>org/hr/entity/ConfigFileThirdKind.hbm.xml</value>
<value>org/hr/entity/ConfigMajor.hbm.xml</value>
<value>org/hr/entity/ConfigMajorKind.hbm.xml</value>
<value>org/hr/entity/ConfigPrimaryKey.hbm.xml</value>
<value>org/hr/entity/ConfigPublicChar.hbm.xml</value>
<value>org/hr/entity/ConfigQuestionFirstKind.hbm.xml</value>
<value>org/hr/entity/ConfigQuestionSecondKind.hbm.xml</value>
<value>org/hr/entity/EngageAnswer.hbm.xml</value>
<value>org/hr/entity/EngageAnswerDetails.hbm.xml</value>
<value>org/hr/entity/EngageExam.hbm.xml</value>
<value>org/hr/entity/EngageExamDetails.hbm.xml</value>
<value>org/hr/entity/EngageInterview.hbm.xml</value>
<value>org/hr/entity/EngageMajorRelease.hbm.xml</value>
<value>org/hr/entity/EngageResume.hbm.xml</value>
<value>org/hr/entity/EngageSubjects.hbm.xml</value>
<value>org/hr/entity/HumanFile.hbm.xml</value>
<value>org/hr/entity/HumanFileDig.hbm.xml</value>
<value>org/hr/entity/MajorChange.hbm.xml</value>
<value>org/hr/entity/SalaryGrant.hbm.xml</value>
<value>org/hr/entity/SalaryGrantDetails.hbm.xml</value>
<value>org/hr/entity/SalaryStandard.hbm.xml</value>
<value>org/hr/entity/SalaryStandardDetails.hbm.xml</value>
<value>org/hr/entity/Training.hbm.xml</value>
<value>org/hr/entity/Users.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">
org.hibernate.dialect.SQLServerDialect
</prop>
<prop key="hibernate.show_sql">true</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
</props>
</property>
</bean>
<!--<tx:annotation-driven transaction-manager="txManager"/>
--></beans>struts-config.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"><struts-config>
  <form-beans >
    <form-bean name="humanFileForm" type="org.hr.struts.form.HumanFileForm" />
    <form-bean name="salaryStandardCheckInForm" type="org.hr.struts.form.SalaryStandardCheckInForm"/>
  </form-beans>
  <global-exceptions />
  <global-forwards />
  <action-mappings >
    <action
      attribute="humanFileForm"
      input="/index.jsp"
      name="humanFileForm"
      parameter="status"
      path="/humanFile"
      scope="request"
      type="org.springframework.web.struts.DelegatingActionProxy">
      <forward name="homepage" path="" />   
    </action>
    
    <!--薪酬标准登记Action-->
    <action 
    path="/salaryStandardCheckIn" 
    name="salaryStandardCheckInForm" 
    scope="request" 
    parameter="status"
    type="org.springframework.web.struts.DelegatingActionProxy"
    >
     <forward name="salaryStandardCheckIn" path="/WEB-INF/page/salary_standard_manage/salary_standard_checkin.jsp"/>
    </action>
  </action-mappings>

  <message-resources parameter="org.hr.struts.ApplicationResources" />
    <plug-in
className="org.springframework.web.struts.ContextLoaderPlugIn">
<set-property property="contextConfigLocation" value="classpath:applicationContext.xml" />
</plug-in>
</struts-config>求解决办法?

解决方案 »

  1.   

    加断点 自己调 这种问题把调试方法学会了 以后这种问题都不怕了 否则只能一次次的问别人如果不会调试,google搜java eclipse debug
      

  2.   

    打印出super.getHibernateTemplate()为空,换成this.getHibernateTemplate()也是为空?网上搜了一下,没看出所以然?大哥,我会调式的可好,关键是我一调试String id=salaryStandardCheckInBiz.getMaxStandarId();//获得最大薪酬编号,如果没有返回默认 
    这句话就直接出异常了,根本就没有往方法里进,这让我怎么调试啊?
      

  3.   


    this.getHibernateTemplate()都为空了,,怎么可能进去方法里。。配置文件有问题
    看了你的spring配置文件问题不少。。每层都没有注入实例所以getHibernateTemplate为空
    自己去网上找找资料把代码部分:
    try{
    List list = super.getHibernateTemplate().find(hql);
    Iterator itr = list.iterator();
    while(itr.hasNext()) {
    SalaryStandard salaryStandard = (SalaryStandard) list.get(0);
    if(salaryStandard.getStandardId()==null){
    id="1000000001";
    }else{
    id=salaryStandard.getStandardId();//获得薪酬编号
    }
    }这样的取值。。不知道为什么要绕一大圈list还去迭代干什么、?直接String id = "".equals(list.get(0).toString()) ? "10000001" : list.get(0).toString();
      

  4.   

    spring配置里  你要用hibernateTemplate  总要给个名分吧,你都没配 就想 拿来用!!!