Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
spring控制器中的java.lang.StackOverflower错误_Java_Ajax_Angularjs_Jsp_Spring Mvc - Fatal编程技术网

spring控制器中的java.lang.StackOverflower错误

spring控制器中的java.lang.StackOverflower错误,java,ajax,angularjs,jsp,spring-mvc,Java,Ajax,Angularjs,Jsp,Spring Mvc,TreesController.java 这是我的控制器方法,请在此处输入代码 package com.reveal.web.controller; import java.util.List; import org.springframework.http.MediaType; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMa

TreesController.java 这是我的控制器方法,请在此处输入代码

    package com.reveal.web.controller;

    import java.util.List;

    import org.springframework.http.MediaType;
    import org.springframework.stereotype.Controller;
    import org.springframework.ui.ModelMap;
    import org.springframework.web.bind.annotation.RequestMapping;
    import org.springframework.web.bind.annotation.RequestMethod;
    import org.springframework.web.bind.annotation.ResponseBody;

    import com.reveal.web.controller.EnsureCapacity.Technology;

    @Controller
    public class TreesController {

        @RequestMapping(value="/mytree",method = RequestMethod.GET)
        public String printWelcome(ModelMap model) {
            return "tree";
        }
        @RequestMapping(value = "/getTechList", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
         public @ResponseBody List<Technology> getTechList(){

             return getTechList();
            } 

        }
package com.reveal.web.controller;
导入java.util.List;
导入org.springframework.http.MediaType;
导入org.springframework.stereotype.Controller;
导入org.springframework.ui.ModelMap;
导入org.springframework.web.bind.annotation.RequestMapping;
导入org.springframework.web.bind.annotation.RequestMethod;
导入org.springframework.web.bind.annotation.ResponseBody;
导入com.reveal.web.controller.ensurecapity.Technology;
@控制器
公共类树控制器{
@RequestMapping(value=“/mytree”,method=RequestMethod.GET)
公共字符串printWelcome(ModelMap模型){
返回“树”;
}
@RequestMapping(value=“/getTechList”,method=RequestMethod.GET,products=MediaType.APPLICATION\u JSON\u value)
public@ResponseBody List getTechList(){
返回getTech列表();
} 
}
这是我的模型类ensurecapity.java 在运行getting stackoverflow exception时,我将这些值从spring控制器返回到我的视图页面,但不知道我错在哪里

package com.reveal.web.controller;

import java.util.ArrayList;
import java.util.List;

public class EnsureCapacity {

    List<Technology> techList = new ArrayList<Technology>(1000);

    public List<Technology> getTechList() {
        if(techList.isEmpty()){      
            ((ArrayList<Technology>) techList).ensureCapacity(1000);
            techList.add(new Technology(1, 0,"Node 1"));
            techList.add(new Technology(0, 1,"Node 1.1"));
            techList.add(new Technology(0, 1,"Node 1.2"));

            techList.add(new Technology(1, 0,"Node 2"));
            techList.add(new Technology(0, 1,"Node 2.1"));
            techList.add(new Technology(0, 1,"Node 2.2"));
            techList.add(new Technology(0, 1,"Node 2.3"));
            techList.add(new Technology(1, 0,"Node 3"));
            techList.add(new Technology(0, 1,"Node 3.1"));
            techList.add(new Technology(0, 1,"Node 3.2"));


            techList.add(new Technology(1, 0,"Node 4"));
            techList.add(new Technology(0, 1,"Node 4.2"));
            techList.add(new Technology(0, 1,"Node 4.3"));
            techList.add(new Technology(0, 1,"Node 4.4"));

            techList.add(new Technology(1, 0,"Node 5"));
            techList.add(new Technology(0, 1,"Node 4.5"));
            techList.add(new Technology(0, 1,"Node 4.6"));
            techList.add(new Technology(1, 0,"Node 6"));

            techList.add(new Technology(0, 1,"Node 6.1"));

            techList.add(new Technology(0, 1,"Node 6.2"));

            techList.add(new Technology(0, 1,"Node 6.3"));

            techList.add(new Technology(0, 1,"Node 6.4"));

            techList.add(new Technology(0, 1,"Node 6.5"));

            techList.add(new Technology(0, 1,"Node 6.6"));

            techList.add(new Technology(0, 1,"Node 6.7"));

            techList.add(new Technology(0, 1,"Node 6.8"));
            techList.add(new Technology(1, 0,"Node 7"));
            techList.add(new Technology(0, 1,"Node 7.1"));
            techList.add(new Technology(1, 0,"Node 8"));
            techList.add(new Technology(0, 1,"Node 8.1"));
            techList.add(new Technology(0, 1,"Node 8.2"));
            techList.add(new Technology(0, 1,"Node 8.3"));
            techList.add(new Technology(0, 1,"Node 8.4"));
            techList.add(new Technology(0, 1,"Node 8.5"));
            techList.add(new Technology(0, 1,"Node 8.6"));
            techList.add(new Technology(0, 1,"Node 8.7"));
            techList.add(new Technology(0, 1,"Node 8.8"));
            techList.add(new Technology(0, 1,"Node 8.9"));

            techList.add(new Technology(0, 1,"Node 8.10"));
            techList.add(new Technology(0, 1,"Node 8.11"));
            techList.add(new Technology(0, 1,"Node 8.12"));
            techList.add(new Technology(0, 1,"Node 8.12"));
        }
        return techList;
    }


    public void setTechList(List<Technology> techList) {
        this.techList = techList;
    }

    class Technology {

        private int Id;
        private int pId;
        private String techName;

        public int getId() {
            return Id;
        }

        public void setId(int Id) {
            this.Id = Id;
        }

        public int getpId() {
            return pId;
        }

        public void setpId(int pId) {
            this.pId = pId;
        }

        public String getTechName() {
            return techName;
        }

        public void setTechName(String techName) {
            this.techName = techName;
        }

        public Technology(int Id, int pId, String techName) {
            this.Id = Id;
            this.pId = pId;
            this.techName = techName;
        }
    }
}`
package com.reveal.web.controller;
导入java.util.ArrayList;
导入java.util.List;
公共类保证{
List techList=新阵列列表(1000);
公共列表getTechList(){
if(techList.isEmpty()){
((ArrayList)techList)。确保资本充足率(1000);
添加(新技术(1,0,“节点1”);
添加(新技术(0,1,“节点1.1”);
添加(新技术(0,1,“节点1.2”);
添加(新技术(1,0,“节点2”);
添加(新技术(0,1,“节点2.1”);
添加(新技术(0,1,“节点2.2”);
添加(新技术(0,1,“节点2.3”);
添加(新技术(1,0,“节点3”);
添加(新技术(0,1,“节点3.1”);
添加(新技术(0,1,“节点3.2”);
添加(新技术(1,0,“节点4”);
添加(新技术(0,1,“节点4.2”);
添加(新技术(0,1,“节点4.3”);
添加(新技术(0,1,“节点4.4”);
添加(新技术(1,0,“节点5”);
添加(新技术(0,1,“节点4.5”);
添加(新技术(0,1,“节点4.6”);
添加(新技术(1,0,“节点6”);
添加(新技术(0,1,“节点6.1”);
添加(新技术(0,1,“节点6.2”);
添加(新技术(0,1,“节点6.3”);
添加(新技术(0,1,“节点6.4”);
添加(新技术(0,1,“节点6.5”);
添加(新技术(0,1,“节点6.6”);
添加(新技术(0,1,“节点6.7”);
添加(新技术(0,1,“节点6.8”);
添加(新技术(1,0,“节点7”);
添加(新技术(0,1,“节点7.1”);
添加(新技术(1,0,“节点8”);
添加(新技术(0,1,“节点8.1”);
添加(新技术(0,1,“节点8.2”);
添加(新技术(0,1,“节点8.3”);
添加(新技术(0,1,“节点8.4”);
添加(新技术(0,1,“节点8.5”);
添加(新技术(0,1,“节点8.6”);
添加(新技术(0,1,“节点8.7”);
添加(新技术(0,1,“节点8.8”);
添加(新技术(0,1,“节点8.9”);
添加(新技术(0,1,“节点8.10”);
添加(新技术(0,1,“节点8.11”);
添加(新技术(0,1,“节点8.12”);
添加(新技术(0,1,“节点8.12”);
}
返回技术列表;
}
公共无效设置列表(列表技术列表){
this.techList=techList;
}
课堂技术{
私有int-Id;
私有int-pId;
私有字符串techName;
公共int getId(){
返回Id;
}
公共无效集合Id(内部Id){
这个.Id=Id;
}
公共int getpId(){
返回pId;
}
公共无效设置pId(内部pId){
this.pId=pId;
}
公共字符串getTechName(){
返回techName;
}
public void setTechName(字符串techName){
this.techName=techName;
}
公共技术(int-Id、int-pId、String-techName){
这个.Id=Id;
this.pId=pId;
this.techName=techName;
}
}
}`

在这里,您在一个无限循环中调用控制器的方法
getTechList
,该方法会导致stackoverflowException

 public @ResponseBody List<Technology> getTechList(){

         return getTechList();
        } 
public@ResponseBody List getTechList(){
返回getTech列表();
} 
您必须调用:
newensurecapacity().getTechList()而不是
getTechList()