Annotation | Meaning |
@RestController | Defines Class that provides REST APIs endpoints methods |
@RequestMapping(“/myapp”) | Defines endpoint for the overall API Class |
@GetMapping(“/info”) @GetMapping(“/students/{studentId}”) | Defines Method that provides API endpoint implementation |
(@PathVariable int studentId) | Defines Variable containing data in endpoint link |
@RestController
@RequestMapping("/api")
public class CrudRestController {
@GetMapping("/students")
public List<Student> getStudents() {
//POJO returned is automatically converted
//to JSON by Spring REST using Jackson
return studentList;
}
@GetMapping("/students/{studentId}")
public Student getStudent(@PathVariable int studentId) {
return studentList.get(studentId);
}
}