StackOverflowError是由于当前线程的栈满了 ,也就是函数调用层级过多导致。
比如死递归。
如:
public String homePage(){
this.findAllNews();
return "shouye";
}
public String findAllNews(){
List newslist= hotnewsService.findAll();
HotnewsDto hotnews= (HotnewsDto) newslist.get(0);//得到第一条新闻
String content=hotnews.getContent();
String subcontent=content.substring(0, 80);//截取这条新闻信息内容在首页部分显示
super.setRequestAttribute("hotnews", hotnews);
super.setRequestAttribute("newslist", newslist);
super.setRequestAttribute("subcontent", subcontent);
return homePage;
}
如红色标记处,这样子调用的方法,相当于一个无限循环了!
解决办法:
将 findAllNews方法的返回值设为 void 即可