小白求救 DAO的问题
ICustomerDAO.getaa()
DAO里面的方法一用就抛空指针 检查了下配置文件没发现什么错误 蒙圈了
下面是全部代码
CustCustomerAction.java
import java.io.Serializable;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import net.sf.json.JSONObject;
import org.apache.struts2.interceptor.ApplicationAware;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;
import org.hibernate.criterion.Restrictions;
import com.javalines.hibernate.dao.base.IBaseDAO;
import com.javalines.hibernate.dao.cust.ITbCustCustomerDAO;
import com.javalines.hibernate.page.EntityView;
import com.javalines.hibernate.pojo.cust.TbCustCustomer;
import com.javalines.struts2.action.base.BaseAction;
import com.javalines.util.AjaxUtils;
public class CustCustomerAction extends BaseAction<TbCustCustomer> implements
ServletRequestAware, ServletResponseAware, SessionAware,
ApplicationAware {
public final static String ID_LIST_PARAM = "idList";
public final static String PAGE_NUM_PARAM = "nowPage";
// request
protected HttpServletRequest request;
// response
protected HttpServletResponse response;
// HTTP session
protected Map<String, Object> session;
// application
protected Map<String, Object> application;
private ITbCustCustomerDAO ICustomerDAO;
public ITbCustCustomerDAO getICustomerDAO() {
return ICustomerDAO;
}
public void setICustomerDAO(ITbCustCustomerDAO customerDAO) {
ICustomerDAO = customerDAO;
}
public void setApplication(Map<String, Object> arg0) {
this.application = arg0;
}
public void setSession(Map<String, Object> arg0) {
this.session = arg0;
}
public void setServletResponse(HttpServletResponse arg0) {
this.response = arg0;
}
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
public IBaseDAO<TbCustCustomer, Serializable> getEntityDAO() {
// TODO Auto-generated method stub
return null;
}
public void checkLoginName(){
try{
String username = request.getParameter("username");
System.out.println(ICustomerDAO.getaa());
AjaxUtils.renderJson(json);
}catch(Exception e){
e.printStackTrace();
}
}
}
struts_mall.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="mallPkg" extends="struts-default" namespace="">
<interceptors>
<!-- 定义拦截堆栈 -->
<interceptor-stack name="myDefault">
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<!-- 定义预定义堆栈 -->
<default-interceptor-ref name="myDefault"></default-interceptor-ref>
<!-- 定义全局结果集 -->
<global-results>
<result name="login">../mall/buyerLogin.jsp</result>
<result name="error">/base/500.jsp</result>
<result name="vcellException">/base/vcellException.jsp</result>
<result name="vcell.invalid.token">/base/duplicateSubmit.jsp</result>
</global-results>
<!-- 配置拦截器完成 -->
<!-- 配置全局异映射 -->
<global-exception-mappings>
<exception-mapping result="error" exception="java.lang.NullPointerException"></exception-mapping>
<exception-mapping result="error" exception="java.lang.ArithmeticException"></exception-mapping>
<exception-mapping result="error" exception="java.lang.Exception"></exception-mapping>
<exception-mapping result="vcellException" exception="com.javalines.system.VCellException"></exception-mapping>
</global-exception-mappings>
<action name="CustCustomerAction" class="com.javalines.struts2.action.cust.CustCustomerAction">
<result name="success">/result.jsp</result>
</action>
</package>
</struts>
ITbCustCustomerDAO.java
import java.io.Serializable;
import com.javalines.hibernate.dao.base.IBaseDAO;
import com.javalines.hibernate.pojo.cust.TbCustCustomer;
public interface ITbCustCustomerDAO extends IBaseDAO<TbCustCustomer,Serializable> {
public String getaa();
}
TbCustCustomerDAOImpl.java
import java.io.Serializable;
import com.javalines.hibernate.dao.base.BaseDAO;
import com.javalines.hibernate.pojo.cust.TbCustCustomer;
public class TbCustCustomerDAOImpl extends BaseDAO<TbCustCustomer,Serializable> implements
ITbCustCustomerDAO {
@Override
public Class<TbCustCustomer> getEntityClass() {
return TbCustCustomer.class;
}
public String generateCodeForApp(String type) {
// TODO Auto-generated method stub
return null;
}
public String generateCodeForCoupon(String type) {
// TODO Auto-generated method stub
return null;
}
public String generateCodeForCouponPurse(String couponNum, String type) {
// TODO Auto-generated method stub
return null;
}
public String generateNumForCoupon(String type) {
// TODO Auto-generated method stub
return null;
}
public String getaa(){
return "bb";
}
}
hibernate?DAO
applicationContext_mall.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"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd">
<bean id="CustCustomerAction" scope="session" class="com.javalines.struts2.action.cust.CustCustomerAction">
<property name="ICustomerDAO" ref="TbCustCustomerDAOImpl"></property>
</bean>
<bean id="TbCustCustomerDAOImpl" class="com.javalines.hibernate.dao.cust.TbCustCustomerDAOImpl">
<property name="hibernateTemplate" ref="ht"></property>
</bean>
</beans>