struts和hibernate组合findByExample空指针异常java.lang.NullPointerException
publicActionForwardquery(ActionMappingmapping,ActionFormform,HttpServletRequestreques...
public ActionForward query(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
QinshiForm qinshiForm= (QinshiForm) form;
Qinshi mybean=new Qinshi();
QinshiDAO mydao=new QinshiDAO();
String strqsname=qinshiForm.getQsname();
//System.out.println(strqsname);
String strgoods=qinshiForm.getGoods();
Integer intnum=qinshiForm.getNum();
String strremark=qinshiForm.getRemark();
Integer intgyid = qinshiForm.getGongyuid();
if(strqsname!=null&&!strqsname.equals("")){
//System.out.println(strqsname);
mybean.setQsname(strqsname);
}
if(strgoods!=null&&!strgoods.equals("")){
mybean.setGoods(strgoods);
}
if(intnum!=null&&!intnum.equals("")){
mybean.setNum(intnum);
}
if(strremark!=null&&!strremark.equals("")){
mybean.setRemark(strremark);
}
if(intgyid!=null&&!intgyid.equals("")){
//System.out.println(intgyid);
mybean.setGongyu((new GongyuDAO()).findById(intgyid));
}
System.out.println(mybean.getGoods());
List lst = (List)mydao.findByExample(mybean);
//List lst=(List)mydao.findByRemark(strremark);
//System.out.println(lst.size());
Iterator it=lst.iterator();
while(it.hasNext()){
Qinshi temp=(Qinshi)it.next();
System.out.println(temp.getGongyu().getName());
}
request.setAttribute("lstqs",lst);
return mapping.findForward("showqinshiForward");
}
public List findByExample(Qinshi instance) {
log.debug("finding Qinshi instance by example");
try {
List results = getSession().createCriteria("myHibernate.Qinshi")
.add(Example.create(instance))
.createCriteria("gongyu")
.add(Example.create(instance.getGongyu())).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
struts和hibernate组合使用,抛出空指针异常。mybean能获得值,但是传到DAO里的findByExample
就没有值了。如果使用List lst=(List)mydao.findByRemark(strremark)(remark为寝室表的一个字段)能获得结果。有没有人帮忙分析下错误原因啊 展开
HttpServletRequest request, HttpServletResponse response) {
QinshiForm qinshiForm= (QinshiForm) form;
Qinshi mybean=new Qinshi();
QinshiDAO mydao=new QinshiDAO();
String strqsname=qinshiForm.getQsname();
//System.out.println(strqsname);
String strgoods=qinshiForm.getGoods();
Integer intnum=qinshiForm.getNum();
String strremark=qinshiForm.getRemark();
Integer intgyid = qinshiForm.getGongyuid();
if(strqsname!=null&&!strqsname.equals("")){
//System.out.println(strqsname);
mybean.setQsname(strqsname);
}
if(strgoods!=null&&!strgoods.equals("")){
mybean.setGoods(strgoods);
}
if(intnum!=null&&!intnum.equals("")){
mybean.setNum(intnum);
}
if(strremark!=null&&!strremark.equals("")){
mybean.setRemark(strremark);
}
if(intgyid!=null&&!intgyid.equals("")){
//System.out.println(intgyid);
mybean.setGongyu((new GongyuDAO()).findById(intgyid));
}
System.out.println(mybean.getGoods());
List lst = (List)mydao.findByExample(mybean);
//List lst=(List)mydao.findByRemark(strremark);
//System.out.println(lst.size());
Iterator it=lst.iterator();
while(it.hasNext()){
Qinshi temp=(Qinshi)it.next();
System.out.println(temp.getGongyu().getName());
}
request.setAttribute("lstqs",lst);
return mapping.findForward("showqinshiForward");
}
public List findByExample(Qinshi instance) {
log.debug("finding Qinshi instance by example");
try {
List results = getSession().createCriteria("myHibernate.Qinshi")
.add(Example.create(instance))
.createCriteria("gongyu")
.add(Example.create(instance.getGongyu())).list();
log.debug("find by example successful, result size: "
+ results.size());
return results;
} catch (RuntimeException re) {
log.error("find by example failed", re);
throw re;
}
}
struts和hibernate组合使用,抛出空指针异常。mybean能获得值,但是传到DAO里的findByExample
就没有值了。如果使用List lst=(List)mydao.findByRemark(strremark)(remark为寝室表的一个字段)能获得结果。有没有人帮忙分析下错误原因啊 展开
3个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询