Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. package com.example.university.controller;
  2.  
  3. import com.example.university.exception.ResourceNotFoundException;
  4. import com.example.university.model.Student;
  5. import com.example.university.service.StudentService;
  6. import org.springframework.beans.factory.annotation.Autowired;
  7. import org.springframework.http.HttpStatus;
  8. import org.springframework.web.bind.annotation.*;
  9.  
  10. import java.util.List;
  11.  
  12. @RestController
  13. @RequestMapping("/student")
  14. public class StudentController {
  15.  
  16.     @Autowired
  17.     private StudentService studentService;
  18.  
  19.  
  20.     @GetMapping("/id")
  21.     public Student getStudent(@RequestParam Long id) throws ResourceNotFoundException {
  22.         return studentService.getStudent(id);
  23.     }
  24.  
  25.     @GetMapping("/age")
  26.     public List<Student> getStudentsAgeGreater(@RequestParam Long age) {
  27.         return studentService.getStudentsAgeGreater(age);
  28.     }
  29.  
  30.     @PostMapping()
  31.     @ResponseStatus(HttpStatus.CREATED)
  32.     public void addStudent(@RequestBody Student student) {
  33.         studentService.addStudent(student);
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement