Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jsf-2/2.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
Java 在Spring Boot中创建路径_Java_Spring_Spring Mvc_Spring Boot - Fatal编程技术网

Java 在Spring Boot中创建路径

Java 在Spring Boot中创建路径,java,spring,spring-mvc,spring-boot,Java,Spring,Spring Mvc,Spring Boot,我有一个SpringBoot项目,我需要创建与学生相关的SpringBoot应用程序。 在第一阶段,我必须在本地主机上发送学生:8080/学生 -而且对我来说效果很好 在第二节中,我必须通过本地主机上的索引发送学生:8080/students/index -而且效果也很好 在第三节中,我必须通过本地主机上的studyProgram发送学生:8080/students/studyProgram,存在问题studyProgram是OBJECT,因此我无法引用它,我尝试了一些不同的方法,因此我请求帮助

我有一个SpringBoot项目,我需要创建与学生相关的SpringBoot应用程序。 在第一阶段,我必须在本地主机上发送学生:8080/学生 -而且对我来说效果很好 在第二节中,我必须通过本地主机上的索引发送学生:8080/students/index -而且效果也很好 在第三节中,我必须通过本地主机上的studyProgram发送学生:8080/students/studyProgram,存在问题studyProgram是OBJECT,因此我无法引用它,我尝试了一些不同的方法,因此我请求帮助

我的学生岛,学生数据库所在的地方

    @Repository
    public class StudentDao {

        private static Map<String,Student>students;
        private static Map<Integer,StudyProgram>programs;
        static
        {
            programs = new HashMap<Integer, StudyProgram>()
            {
                {
                    put(1,new StudyProgram((long)41,"kni"));
                    put(2,new StudyProgram((long)42,"pet"));
                    put(3,new StudyProgram((long)43,"info"));
                    put(4,new StudyProgram((long)44,"iki"));
                }
            };
        }

        static
        {
            students = new HashMap<String, Student>()
            {
                {
                    put("141333", new Student("141333","asd","fgh",programs.get(1)));
                    put("14111", new Student("14111","Trajko","Trajkov",programs.get(2)));
                    put("140000", new Student("140000","Petko","Petkov",programs.get(3)));
                    put("145555", new Student("145555","Mile","Milev",programs.get(4)));
                }
            };
        }

        public Collection<Student> getAllStudents()
        {
            return this.students.values();
        }

        public Student getStudentByIndex(String index){
            return this.students.get(index);
        }
        /* THIS HERE MAKES THE PROBLEM

        public Student getStudentByStudyProgram(Student st){
            return this.students.get(st.getStudyProgramId());
        }
        */

}
最后是我的学习计划课

public class Student {

    String index; //primary key
    String name;
    String lastname;
    //ovde treba studyProgram na kraj
    StudyProgram studyProgram;

    public Student(String index, String name, String lastname, StudyProgram studyProgram)
    {
        this.index = index;
        this.name = name;
        this.lastname = lastname;
        this.studyProgram = studyProgram;
    }
    Student(){}
WITH ALL METHODS IMPLEMENTED HERE

}
public class StudyProgram {
    Long programId;
    String name;

    public StudyProgram(Long programId, String name)
    {
        this.programId = programId;
        this.name = name;
    }
    StudyProgram(){}

}
最后我想问你能不能帮我在localhost:8080/students/studyProgram上绘制一张地图,并根据他们的学习计划绘制地图

在注释的字段中,有需要修复的地方


谢谢

这是如何创建端点以通过学习计划id检索学生

@RequestMapping(value = "/{studyProgramId}",method = RequestMethod.GET)
public Student getStudentByStudyProgram(@PathVariable ("studyProgramId") Long studyProgramId)
{
    return this.studentService.getStudentByStudyProgramId(studyProgramId);
}

唯一需要做的是,实现getStudentByStudyProgramId方法,它应该可以工作。

为什么不创建一个端点,通过学习计划索引或学习计划名称为学生提供信息?@SaWo这是我的问题,我不知道如何创建端点,通过学习计划id为我的学生提供信息,我该怎么做?
public class StudyProgram {
    Long programId;
    String name;

    public StudyProgram(Long programId, String name)
    {
        this.programId = programId;
        this.name = name;
    }
    StudyProgram(){}

}
@RequestMapping(value = "/{studyProgramId}",method = RequestMethod.GET)
public Student getStudentByStudyProgram(@PathVariable ("studyProgramId") Long studyProgramId)
{
    return this.studentService.getStudentByStudyProgramId(studyProgramId);
}