Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.07 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
  21.     @ResponseBody
  22.     public Student getStudent(@RequestParam("id") Long id) throws ResourceNotFoundException {
  23.         return studentService.getStudent(id);
  24.     }
  25.  
  26.     @GetMapping
  27.     @ResponseBody
  28.     public List<Student> getStudentsAgeGreater(@RequestParam("age") Long age) {
  29.         return studentService.getStudentsAgeGreater(age);
  30.     }
  31.  
  32.     @PostMapping()
  33.     @ResponseStatus(HttpStatus.CREATED)
  34.     public void addStudent(@RequestBody Student student) {
  35.         studentService.addStudent(student);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement