Каждый раз, когда я пытаюсь показать результаты со страницы, он загружает результаты в формате json вместо того, чтобы показывать их на странице.
Itначинает загружаться, когда я ввожу URL-адрес, где хранятся объекты / информация, вместо отображения страницы http://localhost:8082/spring-rest-demo/api/students
Если я запускаю сервер и вставляю эту информацию в postman og google chrome, он показывает правильное значениеИнформация без загрузки в виде файла JSON.
так и должно быть
Спасибо
Редактировать:
package com.luv2code.springdemo.rest;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.luv2code.springdemo.entity.Student;
@RestController
@RequestMapping("/api")
public class StudentRestController {
private List<Student> theStudents;
// define @PostConstruct to load the student data only once!
@PostConstruct
public void loadData() {
theStudents = new ArrayList<>();
theStudents.add(new Student("Poornima", "Patel"));
theStudents.add(new Student("Mario", "Rossi"));
theStudents.add(new Student("Mary", "Smith"));
}
// define endpoint for "/Student"-- return list of students
@GetMapping("/students")
public List<Student> getStudents() {
return theStudents;
}
// define endpoint for "/Student({studentid}"-- return list of students at index
@GetMapping("/students/{studentId}")
public Student getStudent(@PathVariable int studentId) {
// just index into the list .... keep it simple for now
return theStudents.get(studentId);
}
}