String str=""; if(tableName=="t_category")
  tableName="Category";
else if(tableName=="t_dictionary")
tableName="Dictionary";

String sql = "select "+queryIDName+" from "+ tableName + " where "+ conditionsIDName+" ="+specialityID;
//select businname from Dictionary where dictionaryid =49
//select d.businName from Dictionary d where d.dictionaryID =49
String hql="select d.businName from Dictionary d where d.dictionaryID =49";


if(tableName.equals("t_xmsp"))
{
//sql="select p.xmmc from t_xmsp p where p.xh in (select c.xmspxh from t_xmssjc c where c.xh in ("+specialityID+"))";
sql="select p.xmmc from TXmsp p where p.xh in (select c.xmspxh from TXmssjc c where c.xh in ("+specialityID+"))";

}
 this.getHibernateTemplate().find("from TXmsp");这个方法有三个参数 tableName queryIDName conditionsIDNamepublic class ExpertSpecialityTag extends TagSupport {
private String expertSpeciality;//1,2
private String tableName;// 表名
private String queryIDName;//查询字段名
private String conditionsIDName;//条件字段名

public String getExpertSpeciality() {
return expertSpeciality;
} public void setExpertSpeciality(String expertSpeciality) {
this.expertSpeciality = expertSpeciality;
} @Override
public int doEndTag() throws JspException {
// TODO Auto-generated method stub
JspWriter out=pageContext.getOut();
ExpertSpecialityTagDAOImpl estd=new ExpertSpecialityTagDAOImpl();
System.out.println(estd);
String specialityDesc=estd.getSpecialityDesc(tableName,queryIDName,conditionsIDName,expertSpeciality);
try
{
out.write(specialityDesc);
}
catch(IOException ioe)
{
ioe.printStackTrace();
}

return TagSupport.SKIP_BODY;//忽略标签体
}
这几个参数有事自定义的标签
为什么执行到this.getHibernateTemplate().find("from TXmsp");就报错了,报null异常

解决方案 »

  1.   

           ExpertSpecialityTagDAOImpl estd=new ExpertSpecialityTagDAOImpl();
            System.out.println(estd);
            String specialityDesc=estd.getSpecialityDesc(tableName,queryIDName,conditionsIDName,expertSpeciality);这里你new的对象,里面的hibernatetemplate肯定为null噻,你需要往里传递这个参数。
      

  2.   

    你看看你的HibernateTemplate对象是否存在 再看看spring中是否配置完全 应该是没配好吧
      

  3.   


    this.getHibernateTemplate().find("from TXmsp");就报错了,报null异常
    说明LZ没有注入啊,必须要注入sessionFactory