StudentController.java 867 Bytes
package com.krunal.reactive.controller;

import com.krunal.reactive.model.Student;
import com.krunal.reactive.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

@RestController
@RequestMapping("/student")
public class StudentController {


    @Autowired
    StudentService studentService;

    @PostMapping("/save")
    public Mono<Student> saveStudent(@RequestBody Student student){
        return studentService.saveStudent(student);
    }

    @PostMapping("/{id}")
    public Mono<Student> getStudent(@PathVariable("id") Long id){
        return studentService.getStudent(id);
    }

    @GetMapping("/students")
    public Flux<Student> students(){
        return studentService.getStudents();
    }
}