Репозиторий
Код: Выделить всё
public interface StudentRepository extends R2dbcRepository{
Flux findByFirstName(String firstName);
}
Код: Выделить всё
public Flux getStudentByName(String name){
return repo.findByFirstName(name);
}
Код: Выделить всё
@GetMapping(value="student/name/{name}")
public Flux getStudentByName(@PathVariable(name = "name",required = true)String name) {
Flux map = service.getStudentByName(name)
.switchIfEmpty(Mono.error(new NoSuchElementException("student not found")))
.map(stu->new ResponseEntity(Mono.just(stu),HttpStatus.OK));
return map;
}
Код: Выделить всё
@GetMapping(value="student/name/{name}")
public Flux getStudentByName(@PathVariable(name = "name",required = true)String name) {
Flux flatMap = service.getStudentByName(name)
.switchIfEmpty(Mono.error(new NoSuchElementException("student not found")))
.flatMap(stu->Flux.just(new ResponseEntity(stu,HttpStatus.OK)));
return flatMap;
}
Я обработал noshelementexception как глобальное исключение.
Как я возвращаю Flux insude insee insee insee insee in insee in insure insee presection .. или наоборот. Flux . Каким подходом я должен пойти, чтобы вернуть объект потока.
Подробнее здесь: https://stackoverflow.com/questions/796 ... g-web-flux