Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.university.controller;
- import com.example.university.exception.ResourceNotFoundException;
- import com.example.university.model.Student;
- import com.example.university.service.StudentService;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.http.HttpStatus;
- import org.springframework.web.bind.annotation.*;
- import java.util.List;
- @RestController
- @RequestMapping("/student")
- public class StudentController {
- @Autowired
- private StudentService studentService;
- @GetMapping("/id")
- public Student getStudent(@RequestParam Long id) throws ResourceNotFoundException {
- return studentService.getStudent(id);
- }
- @GetMapping("/age")
- public List<Student> getStudentsAgeGreater(@RequestParam Long age) {
- return studentService.getStudentsAgeGreater(age);
- }
- @PostMapping()
- @ResponseStatus(HttpStatus.CREATED)
- public void addStudent(@RequestBody Student student) {
- studentService.addStudent(student);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement